โ† Wiki Index / Computation & Algorithms / Random Forest
๐Ÿ’ป Computation & Algorithms

Random Forest

A Random Forest is a non-parametric ensemble learning algorithm that aggregates predictions across a collection of decision trees trained via bootstrap resampling and randomized node-level feature subset selection.

A Random Forest is a non-parametric supervised ensemble learning method in computation and algorithms used for classification, regression, and survival analysis. Formalized by American statistician Leo Breiman in 2001, the algorithm synthesizes two variance-reduction concepts: Breiman's 1996 bootstrap aggregating (bagging) procedure and the random subspace method introduced by Tin Kam Ho in 1995 (alongside randomized split selection studied by Yali Amit and Donald Geman in 1997). Individual deep decision trees exhibit low bias but high variance because small perturbations in the training sample can alter the top split and cascade through the partition hierarchy. By training B unpruned Classification and Regression Trees (CART) on independent bootstrapping replicates and restricting each internal node split to a randomly sampled subset of mtry candidate features, a Random Forest decorrelates the constituent trees so that ensemble averaging suppresses variance without inflating bias.

CART Base Learners and Impurity-Guided Splitting

Binary Recursive Partitioning

Each base learner Tb (b = 1, ..., B) is a binary tree constructed top-down via greedy recursive partitioning of Rp. At an internal node m representing region Rm with Nm observations, a candidate split consists of a predictor variable Xj and a threshold s โˆˆ R that partition Rm into RL(j, s) = {x โˆˆ Rm : xj โ‰ค s} and RR(j, s) = {x โˆˆ Rm : xj > s}, selecting (j*, s*) to maximize the weighted impurity drop:

ฮ”I(m, j, s) = I(Rm) โˆ’ (NL / Nm) I(RL) โˆ’ (NR / Nm) I(RR)

Gini Impurity, Shannon Entropy, and Residual Variance

The impurity functional I(Rm) is matched to the prediction task:

  1. Classification โ€” Gini Impurity: Let pฬ‚mk denote the proportion of class k โˆˆ {1, ..., K} in node m. The Gini index measures expected misclassification probability under random node labeling:

IGini(Rm) = โˆ‘k=1K pฬ‚mk (1 โˆ’ pฬ‚mk) = 1 โˆ’ โˆ‘k=1K pฬ‚mk2

  1. Classification โ€” Information Gain (Shannon Entropy): Node heterogeneity can also be quantified by information entropy:

IEntropy(Rm) = โˆ’ โˆ‘k=1K pฬ‚mk log2(pฬ‚mk)

  1. Regression โ€” Within-Node Variance (MSE): For continuous responses yi โˆˆ R, the node prediction is the sample mean ศณm and impurity is IMSE(Rm) = (1/Nm) โˆ‘xiโˆˆRm (yi โˆ’ ศณm)2. Trees are grown deep (nmin = 1 for classification, nmin = 5 for regression) without post-pruning.

Dual Randomization and Variance Reduction

Bootstrap Aggregating and Random Subspaces

Training B trees on D = {(xi, yi)}i=1n combines two randomization stages:

  1. Row-Wise Bootstrap Resampling: Draw Db* of size n uniformly with replacement from D.
  2. Column-Wise Random Feature Subspace: At each node split, draw Mnode โŠ‚ {1, ..., p} of size mtry โ‰ค p without replacement (mtry = โŒŠโˆšpโŒ‹ for classification; mtry = โŒŠp/3โŒ‹ for regression) and optimize (j*, s*) only over j โˆˆ Mnode.

The ensemble aggregates predictions at a test point x by majority vote or arithmetic averaging: fฬ‚RF(x) = (1/B) โˆ‘b=1B Tb(x).

Mathematical Decomposition of Ensemble Variance

For B identically distributed trees each having variance ฯƒ2 and pairwise correlation ฯ > 0, the variance of the ensemble average is:

Var(fฬ‚RF(x)) = ฯ ฯƒ2 + [ (1 โˆ’ ฯ) / B ] ฯƒ2

As B โ†’ โˆž, the second term vanishes, leaving ฯฯƒ2. In standard bagging (mtry = p), dominant predictors are selected at the root of almost every tree, producing strongly correlated trees (large ฯ). Restricting each node to mtry โ‰ˆ โˆšp random features excludes dominant predictors from (1 โˆ’ mtry/p) of splits, lowering inter-tree correlation ฯ and reducing ensemble variance.

Ensemble MethodTree DepthRow SamplingFeature Sampling (mtry)Bias-Variance Mechanism
Single CART TreePruned via CVFull dataset (n)All features (p)Moderate bias, high variance
Bagging (Breiman, 1996)Deep / unprunedBootstrap with replacementAll features (mtry = p)Reduces (1 โˆ’ ฯ)ฯƒ2/B; high ฯ
Random Forest (Breiman, 2001)Deep / unprunedBootstrap with replacementRandom subset (mtry โ‰ˆ โˆšp or p/3)Reduces both ฯ and ฯƒ2/B via tree decorrelation
Extra-Trees (Geurts et al., 2006)Deep / unprunedFull dataset (n)Random subset + random cut-points sFurther lowers ฯ at slight bias increase
Gradient Boosted TreesShallow (d = 3โ€“8)Subsample without replacementColumn subsamplingSequential stagewise bias reduction via Gradient Descent

Out-of-Bag (OOB) Estimation and Variable Importance

Out-of-Bag Error and 1 โˆ’ eโˆ’1 Coverage

Because each bootstrap sample Db* draws n times with replacement, the probability that observation i is omitted from Db* is:

P(i โˆ‰ Db*) = (1 โˆ’ 1/n)n โ†’ eโˆ’1 โ‰ˆ 0.3679 as n โ†’ โˆž

Each tree trains on ~63.2% of the data, leaving ~36.8% as an Out-of-Bag (OOB) validation set. Predicting each observation xi using only the ~B/3 trees for which i was out-of-bag yields an unbiased internal validation error during training. By the Strong Law of Large Numbers, as B โ†’ โˆž the generalization error converges almost surely to a limiting bound without overfitting.

Gini Importance vs. Permutation Feature Importance

Random Forests rank predictor relevance via two primary metrics:

  1. Mean Decrease Impurity (MDI / Gini Importance): Sums weighted impurity reductions (Nm/n)ฮ”I(m, j, s) across all nodes splitting on Xj, averaged over B trees. MDI is fast but favors continuous or high-cardinality variables with more cut-points.
  2. Permutation Importance (Mean Decrease Accuracy, MDA): Permutes the values of Xj within the OOB sample of each tree b and measures the resulting drop in OOB accuracy (or rise in MSE). Permutation importance provides an unbiased ranking for genome-wide association studies and ecological modeling.

Frequently Asked Questions

Can a Random Forest overfit if the number of trees B is made too large?

No. Because the trees are conditionally independent and identically distributed given the training set, increasing B computes a more precise Monte Carlo approximation to Eฮ˜[T(x; ฮ˜)], driving the finite-sample term (1 โˆ’ ฯ)ฯƒ2/B toward zero without increasing model capacity.

Why do Random Forests struggle to extrapolate linear trends outside the training domain?

Every leaf predicts the local average ศณm of training responses within that box, so a Random Forest prediction is always bounded within [ymin, ymax] and predicts a flat plateau outside the training domain rather than extrapolating a slope as in Linear Regression.

Why is permutation importance preferred over Gini importance in bioinformatics?

When binary genetic variants (SNPs) are analyzed alongside continuous clinical covariates, Gini importance inflates continuous features because they offer more candidate split thresholds s; OOB permutation importance removes this selection bias.

References

  1. Ho, T. K. (1995). Random decision forests. Proceedings of the 3rd International Conference on Document Analysis and Recognition, 1, 278โ€“282. https://doi.org/10.1109/ICDAR.1995.598994
  2. Breiman, L. (1996). Bagging predictors. Machine Learning, 24(2), 123โ€“140. https://doi.org/10.1007/BF00058655
  3. Amit, Y., & Geman, D. (1997). Shape quantization and recognition with randomized trees. Neural Computation, 9(7), 1545โ€“1588. https://doi.org/10.1162/neco.1997.9.7.1545
  4. Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5โ€“32. https://doi.org/10.1023/A:1010933404324
  5. Strobl, C., Boulesteix, A.-L., Zeileis, A., & Hothorn, T. (2007). Bias in random forest variable importance measures: Illustrations, sources and a solution. BMC Bioinformatics, 8, 25. https://doi.org/10.1186/1471-2105-8-25
๐Ÿงฌ Support Open Science
Explore interactive science games on LowKey Games or browse scientific apparel & accessories in the CRV Science Shop.
๐Ÿ’ก Spot an inaccuracy or have primary literature to expand this article?
Submit a citation or revision note using your shared CRV Science / LowKey Games profile ID.
Suggest Revision