Skip to main content

Random Forests and Bagging: Where the Variance Goes

An in-depth look at the mathematical mechanics behind Random Forests, explaining how averaging deep decision trees systematically eliminates variance.

AI-written
Inewgen
13 Aug 2026Source: Dev.to3 min read (0 views)Last updated 20 Sep 2026
Share
Random Forests and Bagging: Where the Variance Goes

Stock photo for illustration only, not from the actual event

Font size
  • Random Forests average deep decision trees to eliminate variance rather than bias.
  • Bagging and Random Feature Selection are what make decision trees diverse.
  • Variance formulas prove why adding the thousandth tree yields diminishing returns.
  • Out-of-bag estimation leverages roughly 37 percent of unused bootstrap data.

A random forest averages many deep trees, each fitted to a different random view of the data. This averaging process cannot make individual trees better on their own and it cannot remove bias. What it successfully removes is variance, and the exact amount can be derived through simple arithmetic that also explains why adding the thousandth tree does nothing meaningful.

Bagging is the first mechanism, where each tree is fitted on a bootstrap sample drawn with replacement, ensuring every tree observes a distinct dataset and makes unique mistakes. Random feature selection is the second component, allowing the tree to consider only a random subset of columns at every split, preventing a single dominant feature from dictating the root of every tree.

decision tree diagram

Stock photo for illustration only, not from the actual event

Individual trees are grown deep and left unpruned, creating low-bias, high-variance estimators that adapt tightly to training data. This volatile behavior serves as the ideal ingredient for averaging, contrasting sharply with the shallow stumps utilized by boosting algorithms.

60.6Mean individual squared error of a single tree
1.0Ensemble prediction squared error
37%Proportion of out-of-bag rows unused per tree

Taking a held-out row with a true value of 41 predicted by five trees yielding values of 30, 45, 38, 52, and 35, the mean individual squared error calculates to 60.6. Meanwhile, the ensemble prediction averages out to 40, resulting in an ensemble squared error of just 1.0, demonstrating that member disagreement functions as the core mechanism rather than a defect.

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

From a statistical standpoint, model disagreement is not a flaw to minimize but the primary engine of ensemble learning. If an ensemble consists of identical trees, the spread term drops to zero and ensemble error equals individual error. Every design choice in a random forest intentionally maximizes this member disagreement.

statistical graph data

Stock photo for illustration only, not from the actual event

For validation purposes, setting oob_score=True in scikit-learn leverages the approximately 37 percent of rows left out during bootstrap sampling to provide an honest held-out estimate without wasting precious training data. However, if correlated rows such as repeat customer entries span across multiple rows, out-of-bag validation can leak data unless grouped splits are utilized.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article