What is a random forest?
A random forest is an ensemble learning method that combines, by voting or averaging, the predictions of many decision trees each trained on random subsets of the training data and features.
It differs from gradient boosting in how trees are built: random forest trees are trained independently and in parallel, while gradient boosting adds each tree in sequence to correct the previous ones. It is far more resistant to overfitting than a single decision tree.
- Topic
- Machine learning, models and training
- Also known as
- Random forests
- Origin
- 2001, Leo Breiman
How a random forest works
- For each tree a random sample is drawn from the training data with replacement, a method called bagging.
- Each split considers only a random subset of features, which keeps trees from looking alike.
- Trees usually grow deep without pruning; each is error-prone but their errors differ.
- For classification the trees' votes, or their averaged class probabilities, give the result; for regression their outputs are averaged.
In more detail
Out-of-bag (OOB) error estimation
Because each bootstrap sample draws roughly 63.2% of unique training rows, the remaining 36.8% or so, called out-of-bag (OOB) samples, can evaluate each tree without needing a separate validation split. OOB error provides a built-in, largely unbiased estimate of generalisation performance during training.
Key hyperparameters
Key hyperparameters include the number of trees (n_estimators), the number of features tried at each split (typically the square root of the feature count for classification and a third of it for regression) and tree depth or minimum leaf size to limit memory use and noise fitting.
Commonly confused terms
| Term | How it differs |
|---|---|
| Bagging and Extra Trees | Bagging uses all features at every split when building bootstrap trees, whereas random forest additionally restricts each split to a random subset of features to decorrelate the trees further. Extra Trees (Extremely Randomized Trees) goes one step further by choosing split thresholds at random. |
Why a random forest matters for on-premises AI
A random forest gives strong results on tabular company data with little tuning, needs no GPU and runs comfortably on in-house CPU servers. Trees train in parallel, so it is fast on multi-core servers. It produces feature importance scores showing each feature's contribution, but a single decision's reasoning is not as easy to read as in one tree and may need extra explanation methods.
An insurer trains a random forest to score claims by fraud risk; high-scoring claims go to its in-house review team first.
Common questions
What is the difference between a random forest and gradient boosting?
A random forest trains trees independently and in parallel, then combines them. Gradient boosting adds trees in sequence, each correcting earlier errors; it often gives higher accuracy but needs more careful tuning.
Does a random forest overfit?
Far less than a single deep tree. Adding more trees usually does not cause overfitting, though tree depth may still be limited for noisy data.
Related terms
- Decision tree
- Ensemble learning
- Gradient boosting
- Overfitting
- Classification
- Feature importance
- Regression
Sources
In the glossary: Glossary, R to Z