Random Forest

Machine Learning
Introduced by
Breiman, L.
Year
2001
Type
Ensemble (bagging of decision trees)

What does it do?

Random Forest is an ensemble learning method, introduced by Leo Breiman in 2001, that grows many decision trees on bootstrap samples of the data and combines their predictions by vote (classification) or averaging (regression).

Averaging over many trees that differ from one another usually gives more accurate and more stable predictions than any single tree.

The intuition behind the method

A single decision tree grown deeply fits the training data closely but is unstable: a small change in the data can produce a noticeably different tree. Random Forest builds many trees, each on a slightly different random view of the data, and combines their outputs. Because the individual trees make errors that are only partly correlated, averaging their predictions reduces variance to the extent that those errors do not coincide. Bootstrap sampling and random feature selection are used to decorrelate the trees, which is why the forest is usually more reliable than one tree on its own.

History

Random Forests were presented by Leo Breiman in 2001 (Breiman, 2001), as an ensemble of decision trees grown on bootstrap samples with random feature selection at each split. The method is widely used in practice for tabular data. Its two ingredients, bootstrap aggregation and random feature selection, have their own earlier development, which is not covered here.

When to use it

Choose Random Forest for predictive modelling of tabular data with many features, where the relationships may be nonlinear or involve interactions, and where accuracy matters more than explicit coefficients. The method makes few distributional assumptions, so normality of the data is not required, and it can be applied to mixed feature types. Do not choose it when the goal is to report the size and direction of individual effects, or when predictions must extrapolate beyond the range of the training outcomes. With very small samples, deep trees can overfit and cross-validation results become unreliable, so simpler models such as logistic or linear regression should be considered as a comparison. Most implementations expect categorical variables to be encoded numerically, and hyperparameter tuning is recommended.

Limitations and considerations

  • No coefficients: the model does not give a direction or size of effect for each predictor, and a feature-importance ranking is not an effect estimate.
  • Hyperparameters such as the number of features considered per split and the tree depth or minimum leaf size need tuning, and large forests require more memory and computation.
  • On small samples, deep trees can overfit and cross-validation results can become misleading.
  • For regression, predictions are averages of training outcomes and cannot extrapolate beyond the range of those outcomes.
  • Feature-importance estimates can be unstable and non-reproducible at small sample sizes.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Strong accuracy on tabular data for both classification and regression, often without extensive feature transformation.
  • Bagging combined with random feature selection at each split reduces variance; adding more trees does not by itself make the forest overfit, although deep trees fitted to very small datasets still can.
  • Out-of-bag error gives an internal estimate of prediction error without a separate hold-out fold, which is useful when data are limited.
  • Built-in feature importance provides a ranking of predictors directly from the fitted model.
  • Captures nonlinear effects and interactions among features without the analyst specifying them in advance.

Applications

  • Classification and regression on tabular data with many features.
  • Variable selection and ranking via native feature importance.
  • Risk scoring and prediction where robustness matters more than explicit coefficients.
  • Baseline modelling before trying more complex ensembles such as gradient boosting.

How it works

How it works

1

Each tree is grown on a bootstrap sample: observations drawn at random, with replacement, from the training set, so every tree sees a slightly different dataset. The observations not drawn into a given sample form its out-of-bag set, which can be used to estimate prediction error without setting aside a separate hold-out fold.

2

At each split in every tree, only a random subset of the available features is considered as candidates, rather than all features. Because a dominant predictor is not always available as a candidate, the trees become less alike, so their errors are less likely to coincide. This decorrelation is what allows averaging to reduce variance below that of any single tree, to the extent that the trees' errors are not strongly correlated.

3

Each tree produces its own prediction, and the forest combines them: a majority vote across trees for classification, or the average of their outputs for regression. Averaging reduces the variance of the individual trees to the extent that their errors are not strongly correlated.

Formula
\hat{y} = \text{mode/mean of } T \text{ trees}

Common pitfalls

  • Relying on in-sample performance, or on the out-of-bag error alone, without an independent train/test split or cross-validation.
  • Ignoring class imbalance instead of re-weighting classes or resampling (in scikit-learn, class_weight='balanced' is one way to re-weight).
  • Reporting only accuracy without F1 and AUC alongside it, particularly when classes are imbalanced.
  • Treating a feature-importance ranking from a small sample as stable.
  • Accepting default hyperparameters without tuning the features considered per split and the tree depth or leaf size; the number of trees mainly needs to be large enough for the out-of-bag error to stabilise.
  • Applying the default bootstrap to time-ordered data without accounting for temporal dependence, which can make error estimates optimistic.

Frequently asked questions

How many trees should the forest have?

More trees reduce variance and stabilise the averaged prediction, at the cost of more computation and memory. A practical approach is to increase the number of trees until the out-of-bag error stops improving.

Does Random Forest overfit?

It is resistant to overfitting in the usual sense, because bagging and random feature selection decorrelate the trees and average out their individual errors. The main risk arises when many deep trees are fitted to a very small dataset; there the model can overfit and cross-validation results become misleading.

Can I trust the feature importance?

Feature importance is useful for ranking predictors, but at small sample sizes it can be unstable and non-reproducible, so treat small-sample rankings with caution. Checking whether the ranking holds across resamples or random seeds is a simple safeguard, and complementary tools such as SHAP analysis can also be used to examine each feature's contribution.

What should I check before and after fitting?

Beforehand, handle missing values, encode categorical variables, and set up a train/test split or k-fold cross-validation. Afterwards, evaluate the out-of-bag error, run cross-validation, and inspect feature importance, including whether the ranking is stable across resamples.

How should I read the outputs?

Vote fractions for classification, or averaged predictions for regression, are not automatically calibrated probabilities, so treat class vote shares as ranking scores unless a separate calibration step has been applied. The out-of-bag error estimates generalisation error for the fitted settings without a hold-out fold; compare it with cross-validation results, and if the two diverge markedly, check the data split and the tuning procedure. Treat feature-importance rankings as provisional if they change across resamples or random seeds.

Related methods

Sources

  1. Breiman, L. (2001). Random Forests. Machine Learning, 45, 5–32.

    Open DOI reference
  2. James, G., Witten, D., Hastie, T. & Tibshirani, R. (2013). An Introduction to Statistical Learning (Ch. 8). Springer.

    ISBN: 978-1-4614-7138-7
  3. 2016_Book_StatisticalLearningFromARegres, Section 5.3.5 'Dependence', p. not recorded