Skip to main content

What is a random forest?

The AI Glossary

In our classes, we often pause to explain the ideas behind AI and the language used to describe it. These posts grew out of those conversations. They’re for anyone who would like to understand AI better, with no technical background assumed.

A random forest combines the predictions of many decision trees. A decision tree follows a sequence of questions about input characteristics until it reaches a prediction. A forest fits multiple trees with deliberate differences between them, then combines their answers. This is an ensemble: a collection of models used together.

In a common version, each tree is trained on a sample drawn from the original data with replacement. “With replacement” means that some examples may appear more than once and others may not appear in that tree’s sample. At each branching point, the learning procedure also considers only a randomly selected subset of the available features.

These choices encourage the trees to differ. If every tree made exactly the same mistakes, combining them would add little. When their errors differ, averaging can make the overall prediction less sensitive to accidental details in one training sample.

For a numerical prediction, the forest usually averages tree outputs. For classification, implementations may combine votes or average estimated class probabilities. Those are related procedures, but not identical. The word “forest” does not specify every implementation detail.

Random forests are useful candidates for structured data, such as tables containing measurements, categories and recorded history. They can capture relationships that are not well described by a straight line. They can still overfit, perform poorly on unfamiliar populations or learn an inappropriate target. They are not guaranteed to outperform every single tree or other model.

Some software reports feature importance: a measure of how much an input contributes to predictions by a particular calculation. This is not a measure of causation, and different importance methods have different weaknesses, particularly when inputs are correlated.

A care-transitions team studying post-discharge follow-up might compare a random forest with logistic regression and a simple clinical rule. The relevant questions are whether it predicts missed follow-up better on new cases, how dependable its probabilities are and whether outreach staff can use the result constructively. A forest that recognizes historical access barriers should not turn those barriers into a reason to withhold support.

Sources: scikit-learn — Ensembles: Random Forests and Bagging

Further reading from Harvard Chan: Public Health Perspectives — To Meet Future Needs, Health Care Leaders Must Look at the Data (Science) (2022).

To learn more, take a look at the AI in Health Care Certificate of Specialization from the Advanced Learning Academy at Harvard T.H. Chan School of Public Health. You can take an individual course or work toward the full certificate.


I’m a doctor, not a statistician. I teach the AI in Health Care Certificate of Specialization with Dr. Heather Mattie, a statistician and co-director of Harvard Chan’s Health Data Science master’s program. For more on data science and statistics, see Harvard Chan’s Health Data Science resources.

AI is a fast-moving field. This explanation reflects our class discussions and related material at the time of writing. Terminology, capabilities and tools may change.

For suggested additions or corrections, please email me at tpanch@hsph.harvard.edu.

Dr. Trishan Panch
Program Director, AI in Health Care
Harvard T.H. Chan School of Public Health — Advanced Learning Academy

Lead with AI in Health Care

The AI Pragmatist is a monthly newsletter from ALA faculty, with new explainers & essays from the Advanced Learning Academy