Search

Search papers and lessons

Ensemble Learning

Level 3 · 15 min read

Ensemble learning combines many imperfect models into one predictor, and it works because averaging cancels out the errors that individual models make differently.

On this page

  • Colour = topic mix
  • Probability
  • Learning basics
  • Classical models
  • Losses & regularization
  • Discrete math
  • Sign in to see your progress

TL;DR

Ensemble learning trains several models on the same problem and combines their predictions, usually by averaging or voting. One model is often noisy, but the mistakes of different models do not always point the same way, so combining them cancels part of the error. The result is usually more accurate and more stable than any single member.

The trick only works if the members disagree in useful ways. Identical models give you nothing new, so every ensemble method is really a recipe for making models different from each other while keeping each one good.

Where you'll see it: random forests in tabular machine learning, gradient-boosted trees in many competition and industry systems, and the "model soup" and checkpoint-averaging tricks used to polish large neural networks.

Intuition

Ask a crowd

Suppose you want to guess the weight of an ox at a county fair. One guess from one person is a gamble. Francis Galton, reporting on a contest in 1907, found that the median of about 800 guesses was within a percent of the true weight, even though many individual guesses were far off. The crowd was not smarter than any one person. Each guess had its own random error, and those errors partly cancelled when pooled.

A model is the same kind of guesser. It learns from a finite training set, so it picks up a particular pattern of noise along with the signal. A different training set would produce a different pattern of noise. If you train several models and average them, the parts of their errors that are specific to their own training data tend to cancel, while the shared signal stays.

Why a single model is not enough

A flexible model has low bias but high variance: it follows the training data closely, including its noise, so it overfits and gives different answers on different samples. A rigid model has the opposite problem. Ensembles are the practical way out of this trade-off. Averaging many high-variance models keeps the low bias and shrinks the variance.

510152000.20.40.60.81number of models Mvariance of the average
  • correlation 0.3
  • independent models
Variance of an average of M models, each with variance 1. Independent models shrink like 1/M. Correlated models stop improving at the level of their shared error.

The plot shows the key limit. Adding models helps quickly at first and then flattens. The floor is set by how correlated the models are, which is why the ensemble methods below spend most of their effort on decorrelating their members.

Two families

There are two broad strategies. Parallel ensembles train members independently and average them; the goal is to reduce variance. Sequential ensembles train each member to fix the mistakes of the ones before it; the goal is to reduce bias. Bagging and random forests are the first kind. Boosting is the second.

flowchart LR
  D["Training data"] --> R1["Resample 1"]
  D --> R2["Resample 2"]
  D --> R3["Resample 3"]
  R1 --> M1["Model 1"]
  R2 --> M2["Model 2"]
  R3 --> M3["Model 3"]
  M1 --> A["Average or vote"]
  M2 --> A
  M3 --> A
  A --> P["Final prediction"]

The math

Averaging M predictions

Let f1,…,fMf_1, \dots, f_M be predictors of a target yy, and let fˉ=1M∑m=1Mfm\bar f = \frac{1}{M}\sum_{m=1}^{M} f_m be their average. Each fmf_m has variance σ2\sigma^2 over training sets, and every pair has correlation ρ\rho, meaning covariance ρσ2\rho\sigma^2. The variance of the average is

Var(fˉ)=1M2∑m=1M∑k=1MCov(fm,fk).\mathrm{Var}(\bar f) = \frac{1}{M^2}\sum_{m=1}^{M}\sum_{k=1}^{M}\mathrm{Cov}(f_m, f_k).

There are MM diagonal terms, each equal to σ2\sigma^2, and M(M−1)M(M-1) off-diagonal terms, each equal to ρσ2\rho\sigma^2. So

Var(fˉ)=1M2(Mσ2+M(M−1)ρσ2)=ρσ2+1−ρMσ2.\mathrm{Var}(\bar f) = \frac{1}{M^2}\left(M\sigma^2 + M(M-1)\rho\sigma^2\right) = \rho\sigma^2 + \frac{1-\rho}{M}\sigma^2.

Two limits follow directly. If ρ=0\rho = 0, the variance is σ2/M\sigma^2/M, which goes to zero as MM grows. If ρ>0\rho \gt 0, the variance can never drop below ρσ2\rho\sigma^2, however many models you add. Correlation sets the floor. This is the formula behind the plot above, with σ2=1\sigma^2 = 1.

Averaging does nothing to bias. If every member has the same expected prediction, the average has that same expectation. Ensembles of identical-bias models lower variance only.

Bagging

Bootstrap aggregating, or bagging, trains each member on a bootstrap sample: draw nn points from the nn-point training set with replacement. A given point is missed by one draw with probability 1−1/n1 - 1/n, so it is missed by all nn draws with probability (1−1/n)n(1 - 1/n)^n, which approaches 1/e≈0.3681/e \approx 0.368. Each bootstrap sample therefore contains about 63.2% distinct original points, and the rest are duplicates. The resamples are different enough to make the members less correlated than models trained on the full data. See Bootstrap Sampling for the resampling idea itself.

For regression, the ensemble prediction is the mean of the members. For classification, it is a majority vote, or the average of predicted probabilities.

Random forests

A random forest is bagging of decision trees with one extra step. At each split, the tree may consider only a random subset of the features. This stops one strong feature from dominating every tree, which would make all the trees alike. Lower correlation ρ\rho means a lower floor in the formula above, so the extra randomness often matters more than the extra trees.

Boosting

Boosting builds members one after another. Each new learner focuses on the examples the previous ones got wrong. In AdaBoost, which is the classic version for binary labels y∈{−1,+1}y \in \{-1, +1\}, each example has a weight wiw_i. After training weak learner hth_t with error εt\varepsilon_t (weighted by the current wiw_i), it gets a vote

αt=12ln⁡1−εtεt,\alpha_t = \frac{1}{2}\ln\frac{1 - \varepsilon_t}{\varepsilon_t},

which is large when the learner is accurate. The weights are then updated so that misclassified points gain weight, and the final model is

H(x)=sign⁡(∑t=1Tαtht(x)).H(x) = \operatorname{sign}\left(\sum_{t=1}^{T} \alpha_t h_t(x)\right).

Gradient boosting generalises this: each new tree is fitted to the negative gradient of the loss at the current ensemble, so the same idea works for any differentiable loss.

Worked examples

Example
Three classifiers, majority vote

Each of three classifiers is correct on a new point with probability p=0.7p = 0.7, and their errors are independent. The majority is correct when at least two of the three are correct.

  1. Probability all three are correct: p3=0.73=0.343p^3 = 0.7^3 = 0.343.
  2. Probability exactly two are correct: 3p2(1−p)=3⋅0.49⋅0.3=0.4413p^2(1-p) = 3 \cdot 0.49 \cdot 0.3 = 0.441.
  3. Majority is correct: 0.343+0.441=0.7840.343 + 0.441 = 0.784.

The ensemble is right 78.4% of the time, against 70% for any single member. The gain comes entirely from independence. If the three classifiers always erred together, the majority would be right 70% of the time, the same as one of them.

Example
Averaging correlated regressors

Five regression models each have prediction variance σ2=4\sigma^2 = 4, and every pair has correlation ρ=0.25\rho = 0.25.

  1. Floor from correlation: ρσ2=0.25⋅4=1.0\rho\sigma^2 = 0.25 \cdot 4 = 1.0.
  2. Variance of the average with M=5M = 5: ρσ2+1−ρMσ2=1.0+0.755⋅4=1.0+0.6=1.6\rho\sigma^2 + \frac{1-\rho}{M}\sigma^2 = 1.0 + \frac{0.75}{5}\cdot 4 = 1.0 + 0.6 = 1.6.
  3. Standard deviation of the average: 1.6≈1.26\sqrt{1.6} \approx 1.26, down from 2.02.0 for a single model.
  4. With M=50M = 50: 1.0+0.7550⋅4=1.061.0 + \frac{0.75}{50}\cdot 4 = 1.06. Going from 5 to 50 models buys only a little.
  5. If the same five models were uncorrelated (ρ=0\rho = 0), the variance would be 4/5=0.84/5 = 0.8.

Interpretation: decorrelation is worth more than extra members here. A random forest that drops ρ\rho from 0.25 to 0.05 gets a floor of 0.2 instead of 1.0.

Tradeoffs and failure modes

SituationProblemBetter choice
Single model overfits badly, data is plentifulHigh varianceBagging or random forest
Single model underfits, bias dominatesAveraging will not fix itBoosting, or a more flexible model
Members are nearly identical (same data, same features)Correlation near 1, no gainAdd randomness to data or features
Latency or memory budget is tightMany members cost time and spaceDistil the ensemble into one model (Knowledge Distillation)
Boosting on noisy labelsWeights chase mislabelled pointsBagging, or boosting with a robust loss
Interpretability is requiredAn average of hundreds of trees is opaqueOne tree, or a simpler linear model

Ensembles also cost more to train and serve, and they can hide errors: a wrong but confident majority is still wrong. Always check the ensemble against a held-out split, not against the members' training scores.

History

The idea that pooled judgement beats individual judgement is old. Galton's 1907 ox-weight observation is the usual example. In machine learning, Wolpert described stacking, which learns how to combine member predictions, in 1992. Breiman introduced bagging in 1996, and he later described random forests in 2001 as a method that adds feature randomness to bagged trees.

Boosting came from a theoretical question: could a collection of weak learners, each only slightly better than guessing, be combined into a strong one? Schapire showed in the early 1990s that the answer is yes. Freund and Schapire then produced AdaBoost, which was practical and fast, in the mid-1990s. Friedman's gradient boosting in the early 2000s extended it to general losses.

Ensembles became standard in practice because they were reliable. They rarely needed careful tuning, they handled messy tabular data well, and they regularly won benchmark competitions. Deep learning later adopted the same idea in cheaper forms, such as averaging checkpoints and training several networks with different seeds.

Check yourself

QuestionIn one sentence, what does an ensemble do to variance, and what does it not do to bias?Show answer

Averaging the predictions of several models reduces the variance of the combined prediction, because individual models' training-specific errors partly cancel. It does not reduce bias on its own: if every member has the same expected prediction, the average has that expected prediction too.

QuestionThree independent classifiers are each right with probability 0.6. What is the probability that the majority vote is right?Show answer

Majority is right when at least two of three are right. Exactly three: 0.63=0.2160.6^3 = 0.216. Exactly two: 3⋅0.62⋅0.4=3⋅0.36⋅0.4=0.4323 \cdot 0.6^2 \cdot 0.4 = 3 \cdot 0.36 \cdot 0.4 = 0.432. Total: 0.216+0.432=0.6480.216 + 0.432 = 0.648. The vote is right 64.8% of the time, against 60% for one member.

QuestionWhy does adding more members stop helping once the number of models is large, if their pairwise correlation is ρ>0\rho \gt 0?Show answer

From Var(fˉ)=ρσ2+1−ρMσ2\mathrm{Var}(\bar f) = \rho\sigma^2 + \frac{1-\rho}{M}\sigma^2, the term that shrinks with MM is 1−ρMσ2\frac{1-\rho}{M}\sigma^2, and the term ρσ2\rho\sigma^2 does not depend on MM. Once MM is large, the correlated part dominates and no number of extra members can push the variance below ρσ2\rho\sigma^2. Reducing ρ\rho is the only way to lower that floor.

QuestionA bootstrap sample has n=1000n = 1000 draws from 1000 points. Roughly how many distinct original points does it contain, and why?Show answer

Each point is missed by all draws with probability (1−1/1000)1000≈e−1≈0.368(1 - 1/1000)^{1000} \approx e^{-1} \approx 0.368. So about 63.2% of points appear, which is about 632 distinct points. The other 368 slots are repeats, and that repetition is what makes bagged members differ from one another.

QuestionYou are building a fraud detector. Your gradient-boosted ensemble scores 99% on the training set and 81% on the held-out set. Which step would you take first, and why?Show answer

The gap points to overfitting: the ensemble has memorised training-set quirks. First, check the depth, learning rate, and number of trees, and use early stopping on a validation split so that the number of boosting rounds is chosen from held-out data, not training data. Adding more boosting rounds would not close the gap and can widen it. Also confirm that no training features leak the label.

Sources