How Bagging and Boosting Trade Off Bias Against Variance
Machine LearningModel answerLast updated
Explain how random forests and gradient boosting reshape the bias-variance decomposition, derive the variance of correlated averages, and say when each ensemble is the better choice.
Ensembles Through the Lens of Error Decomposition
For squared loss, the expected prediction error at a point can be split into squared bias, variance, and irreducible noise. Two popular ensemble families, bagging-style methods and boosting-style methods, attack this decomposition from opposite sides.
Write a clear, structured answer covering the following.
- Bagging and Random Forests. Explain why averaging many trees lowers error. Derive the variance of the mean of
nidentically distributed predictors that each have variancesigma^2and pairwise correlationrho. Explain what happens to bias and what limits the variance reduction. - Random Forests versus plain bagging. Describe how per-split feature subsampling changes
rho, and what it costs in return. - Gradient boosting. Explain how fitting learners sequentially to the current errors (the negative gradient of the loss) shapes bias and variance differently from bagging. Explain why an unregularized booster tends to overfit and which tools control this.
- Choosing between them. Under what conditions would you prefer a Random Forest, and under what conditions a gradient boosting machine? Frame your answer in terms of bias, variance, noise level, dataset size, and tuning effort.
Mention how you would diagnose, from training and validation error, which side of the trade-off you are on. Point out common misconceptions where relevant.
Hints
Hint 1
Compute the variance of a sum of n correlated terms: n variance terms plus n(n-1) covariance terms, then divide by n squared. Look at what remains as n grows.
Hint 2
Averaging leaves the expected prediction unchanged, so think about which error component it cannot touch, and what that implies about the kind of base tree you want in a forest.
Hint 3
In boosting, ask what the targets of later trees look like once the real signal is fitted. Then ask which knobs (step size, subsampling, number of rounds, depth) make each correction smaller or less noisy.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Setup
For squared loss with y = f(x) + ε:
Expected error = Bias² + Variance + σ_ε²
No ensemble can reduce the irreducible noise σ_ε². Bagging mainly attacks variance; boosting mainly attacks bias. Each pays for its gains elsewhere.
1. Bagging and Random Forests: variance reduction
Let X₁…X_n be identically distributed with variance σ² and pairwise correlation ρ. Then
Var(mean) = (1/n²)[nσ² + n(n−1)ρσ²] = ρσ² + (1−ρ)σ²/n
Consequences:
- Bias is unchanged. The mean of the averaged predictions equals the mean of one tree's prediction. In fact each tree sees only about 63% unique rows of the data, so bias is marginally above that of a tree on the full data.
- A variance floor exists. As n grows, the second term vanishes and variance approaches ρσ². More trees cannot go below that, so the remaining lever is ρ.
- Use deep trees. Since averaging cannot fix bias, the base learners should have low bias and high variance: fully grown or nearly fully grown trees.
- More trees do not overfit. Generalization error converges as trees are added. Overfitting in a forest is governed by depth and leaf size, not by tree count.
2. How Random Forests lower ρ
Bootstrap samples overlap heavily, and if a few features are strongly predictive, nearly every bagged tree splits on them near the root. The trees look alike and ρ stays high.
A Random Forest considers only a random subset of mtry features at each split (commonly √p for classification, p/3 for regression). Strong features are often unavailable at a given node, so trees follow different structures and their errors decorrelate.
The cost:
- Smaller
mtrylowers ρ. - Smaller
mtryalso raises each tree's σ² and its bias, because it forces weaker splits.
So mtry balances ρσ² against the (1−ρ)σ²/n term and tree bias. It is the main tuning knob. In high dimensions with few relevant features, a small mtry often yields subsets with no useful feature (probability roughly (1 − k/p)^mtry for k relevant of p), so trees split on noise; raise mtry or screen features first.
3. Gradient boosting: bias reduction
Boosting builds an additive model by functional gradient descent:
F_m(x) = F_{m−1}(x) + ν·h_m(x)
where h_m is fitted to the negative gradient of the loss at F_{m−1} (for squared loss, simply the residuals).
Why bias falls.
- Base learners are weak (shallow trees: high bias, low variance).
- Each round targets what the current model still gets wrong, so training loss decreases steadily.
- The sum of M trees can represent far richer functions than any single shallow tree, so bias shrinks as M grows.
Why variance can blow up.
- Once the signal is captured, residuals are mostly noise, and later trees fit it.
- Learners are sequentially dependent: a spurious pattern learned early changes every later target and is never averaged out.
- M acts as a complexity parameter. Training error can reach zero, so adding rounds eventually overfits (unlike a forest).
- Gradients of squared or exponential loss are dominated by outliers.
Regularization.
- Shrinkage (ν): smaller steps mean many small corrections that smooth out noise. It needs more rounds, so ν and M must be tuned together.
- Row and column subsampling: a bagging-like injection of randomness that decorrelates successive trees.
- Tree depth and minimum leaf size: limit the interaction order and how finely noise can be fit.
- Early stopping on a validation set.
- Robust losses (Huber, absolute) when outliers matter.
4. Choosing between them
| Random Forest | Gradient Boosting | |
|---|---|---|
| Main target | Variance | Bias |
| Base learner | Deep, low bias, high variance | Shallow, high bias, low variance |
| More trees | Plateaus, does not overfit | Eventually overfits |
| Tuning sensitivity | Low | High (ν, M, depth, subsampling) |
| Noisy labels/outliers | Fairly robust | Can chase noise |
| Training | Parallel | Sequential |
Prefer a Random Forest when variance is the main risk:
- Noisy labels or high irreducible error.
- Small datasets, where a validation set for tuning is unreliable.
- Outliers in the target.
- Little tuning time, or you need a strong, robust baseline fast.
Prefer gradient boosting when bias is the main risk:
- Large, reasonably clean datasets with complex structure and interactions.
- A tuned forest has plateaued: its bias is that of a deep tree, which averaging cannot remove.
- You can afford careful validation and regularization. On structured tabular data this setup is usually where boosting wins.
Diagnosis.
- Low training error but a large train/validation gap: a variance problem. Use a forest, lower
mtry/raise leaf size, or regularize the booster harder. - Both errors high: a bias problem. Use boosting, deeper trees, or more rounds.
Common mistakes
- Claiming bagging reduces bias. At best it leaves it unchanged.
- Using Var = σ²/n and ignoring correlation, which is the whole reason Random Forests exist.
- Saying a forest overfits as trees are added. Depth and leaf size drive overfitting, not tree count.
- Treating the learning rate as only a speed knob. It is a regularizer that trades off against M.
- Saying "boosting reduces variance" without qualification. Only its regularizers (shrinkage, subsampling) do that.