Recommended resources
The freely available resources this lesson will direct you to.
- Machine Learning Lecture 31 "Random Forests / Bagging" -Cornell CS4780 SP17www.youtube.com
- MIT: Machine Learning 6.036, Lecture 12: Decision trees and random forests (Fall 2020)www.youtube.com
- Randomization Can Reduce Both Bias and Variancejmlr.org
- Bootstrap Aggregating and Random Foresteconomics.ucr.edu
In our previous lesson, we explored the inner workings of decision trees, focusing on how they recursively partition data to create interpretable, rule-based models. While their transparency is a major strength, we concluded by noting their primary weakness: a tendency to overfit the training data. A single, deep decision tree often has high variance, meaning small perturbations in the training set can lead to a drastically different model structure.
Today, we will address this very problem by introducing ensemble methods, a powerful class of algorithms that combine multiple models to achieve superior performance. Our focus will be on deriving the principle of Bootstrap Aggregating (Bagging) and understanding how its most famous implementation, the Random Forest, leverages this principle to build robust models by reducing the variance of individual trees.
The Core Idea: Reducing Variance by Averaging
Before diving into the algorithm, let's establish the statistical foundation. The high variance of a deep decision tree means that its predictions can be unstable. If we could train many different trees on slightly different datasets drawn from the true underlying data distribution and then average their predictions, the errors of the individual trees would tend to cancel each other out, resulting in a more stable, lower-variance prediction.
This is the central tenet of bagging. The improvement is not just heuristic; it has a firm mathematical basis in the bias-variance decomposition.
Consider a set of estimators . If these estimators are independent and identically distributed (i.i.d.) with variance , the variance of their average, , is:
By averaging, we reduce the variance by a factor of . However, in machine learning, we cannot easily generate truly independent models because they are all trained on subsets of the same finite dataset. This means our models will be correlated. If we assume each estimator has variance and the average pairwise correlation between any two estimators is , the variance of the average becomes:
This equation is crucial. It tells us that as we add more estimators (), the second term vanishes, but the variance does not go to zero. It is fundamentally limited by the first term, , which is governed by the correlation between the models. To effectively reduce variance, we must not only average many models but also ensure they are as decorrelated as possible.
Bootstrap Aggregating (Bagging)
The challenge is how to create these multiple models from a single training set. Bagging solves this with a clever statistical technique called bootstrapping. A bootstrap sample is created by drawing data points from the original training set with replacement. This process is repeated times to create new datasets, each the same size as the original.
The video "MIT: Machine Learning 6.036, Lecture 12" provides an excellent visual explanation of this process.
MIT: Machine Learning 6.036, Lecture 12: Decision trees and random forests (Fall 2020)
This segment from an MIT lecture clearly explains the core mechanism of Bagging: creating multiple "fake" datasets via bootstrapping and then aggregating the results.
Please watch the portion from talk about bagging. Focus on understanding how sampling with replacement creates slightly different datasets and how the final prediction is formed through aggregation (averaging or voting).
The full Bagging algorithm is as follows:
- Bootstrap: Generate bootstrap samples from the original training dataset. Due to sampling with replacement, some data points will appear multiple times in a given sample, while others will be absent.
- Train: Fit a model (e.g., a fully grown, unpruned decision tree) independently on each of the bootstrap samples.
- Aggregate: For a new data point, make a prediction with each of the models.
- For regression, the final prediction is the average of the individual predictions.
- For classification, the final prediction is determined by a majority vote among the models.
This process is visualized in the "Bagging" diagram below.

From Bagging to Random Forests
While bagging decision trees is effective, it still suffers from one limitation: the trees can be highly correlated. If the dataset has one or a few very strong predictive features, these features will be selected as the top splits in most of the bootstrapped trees. This leads to a high value of in our variance equation, limiting the overall variance reduction.
The Random Forest algorithm, proposed by Leo Breiman, introduces a simple yet brilliant modification to decorrelate the trees.
At each split within each tree, the algorithm randomly selects a subset of features from the total of available features (). It then finds the best possible split, but only among that random subset of features.
This deliberate restriction prevents individual trees from all latching onto the same dominant features. By forcing some trees to rely on other, perhaps less powerful predictors, the overall structure of the trees becomes more diverse. This directly reduces the correlation between the trees.

The following reading from the paper "Bootstrap Aggregating and Random Forest" provides the mathematical context for how both bagging and the feature randomization of Random Forests contribute to reducing variance.
Bootstrap Aggregating and Random Forest
This paper provides a concise mathematical derivation of the principles behind Bagging and Random Forests, directly addressing our learning objective.
First, read the section on Bootstrap aggregating (Bagging). This part formalizes the bias-variance decomposition and explains how Bagging primarily targets the variance term. Next, read the section on Constructing a random forest. Pay close attention to Equation (16), which is the variance formula for correlated estimators we discussed. The text then explains precisely how Random Forest's random feature projection aims to reduce the correlation \rho, thereby tackling the first term of that equation, which Bagging alone cannot reduce as effectively.
A Deeper Theoretical Insight: Can Random Forests Reduce Bias?
The classical and dominant understanding, as we have just established, is that Random Forests improve over single trees primarily through variance reduction. The averaging process does not systematically change the expected prediction, so the bias remains roughly the same as that of an individual tree.
However, more recent theoretical work has challenged this simple narrative. A fascinating paper published in JMLR argues that under certain conditions, the feature randomization in Random Forests can also reduce bias. This occurs on datasets with what the authors call "hidden patterns."
Imagine a scenario where the true data-generating process depends on two features, X1 and X2. X1 has a strong, obvious linear effect on the outcome. X2 has a weaker but highly non-linear effect that is only active in a narrow range of its values. A greedy decision tree (and thus, a Bagging ensemble) will almost always split on X1 first, as it provides the largest immediate reduction in error. By the time the tree is deep enough to consider splitting on X2, the data has been partitioned so much by X1 that the subtle pattern in X2 is obscured and can no longer be learned effectively. The model is therefore biased against finding the true underlying function.
Random Forests, by sometimes forcing a tree to consider a split on X2 early on (when X1 is not in the random subset of features), can uncover this "hidden pattern." This ability to better capture the true data-generating function results in a reduction of model bias.
Randomization Can Reduce Both Bias and Variance
This paper presents a compelling argument that Random Forests can reduce bias in addition to variance. This provides a more nuanced, modern understanding of the algorithm's power.
Please read the following sections: Start with Section 3, "Random Forests and Hidden Patterns", to grasp the intuition behind the "Hidden2D" case study. Continue to Section 3.1.4, "Bias Variance Decomposition". Table 1 provides the empirical evidence that SFS (Split-Feature Subsetting, i.e., Random Forest) reduces both bias and variance in this case. Finally, read Section 3.2, "Do Random Forests Only Reduce Variance?". This section directly challenges the classical view and shows how the bias of individual trees is lower in the Random Forest compared to the Bagging ensemble.
This insight is a testament to the depth of seemingly simple algorithms and aligns with your goal of building a robust theoretical foundation. While variance reduction remains the primary and most general explanation for the success of Random Forests, understanding their potential for bias reduction offers a more complete picture.
A Practical Advantage: Out-of-Bag Error
The bootstrapping process provides another powerful, "free" benefit: a robust way to estimate the model's generalization error without needing a separate validation set. This is known as the out-of-bag (OOB) error.
For each tree in the forest, about one-third of the original data points were not included in its bootstrap training sample. These are the "out-of-bag" points for that tree. To calculate the OOB error for a single data point , we can make a prediction for it using only the trees for which was out-of-bag. The OOB error is the average error over all such predictions across all data points. This provides an unbiased estimate of the test error, which you get for free during the training process.
The following video provides an exceptionally clear explanation of this concept.
Machine Learning Lecture 31 "Random Forests / Bagging" -Cornell CS4780 SP17
This lecture clip from Cornell CS4780 explains the out-of-bag error, a key advantage of all bagging-based algorithms.
Watch the segment from the killer advantage. The lecturer clearly explains why a train-validation split isn't strictly necessary and derives the concept of using out-of-bag samples to get an unbiased estimate of test performance.
Conclusion
In this lesson, we have moved from the high-variance world of single decision trees to the robust and powerful domain of ensemble learning. We derived the core principles of Bagging and Random Forests, grounded in the mathematics of the bias-variance tradeoff.
Here are the essential takeaways:
- The Bagging Principle: Averaging the predictions of multiple models trained on bootstrap samples of the data reduces the variance of the final prediction.
- Variance of Correlated Models: The effectiveness of averaging is limited by the correlation () between the models, as described by the variance formula .
- Random Forests' Key Innovation: Random Forests improve upon Bagging by introducing random feature selection at each split. This decorrelates the trees (reduces ), allowing for a more significant reduction in overall model variance.
- Bias Reduction: While primarily a variance-reduction technique, Random Forests can also reduce bias in scenarios with "hidden patterns" that greedy tree-building might otherwise miss.
- Out-of-Bag Error: Bagging provides a "free" and unbiased estimate of the test error by using the data points left out of each bootstrap sample for validation.
So far, we have focused on an ensemble method that builds models in parallel to reduce variance. In our next lesson, we will explore a fundamentally different ensemble strategy called Boosting. Boosting builds models sequentially, where each new model focuses on correcting the errors of the previous ones. This approach primarily targets reducing bias, offering a complementary strategy to the methods we've learned today.