Lensa ML

Bagging vs boosting: many trees side by side or one after another

Bagging and boosting both combine many decision trees, models that predict by asking yes-or-no questions about the input. Bagging trains its trees side by side and averages them. Boosting trains them one after another, and each new tree fixes errors the earlier ones left.

2 min read · Lensa ML
Baggingside by side, averaged123+ 17 more treestest error 0.145Boostingin sequence, each × 0.3123+ 17 more treestest error 0.066
training pointone tree (a stump)all 20 trees combined
  1. Both rows learn the same 25 training points from the gradient-boosting explainer: a wavy curve plus noise. Every tree is a stump, a tree with a single question: is x below a threshold? It predicts one value on each side. Test error is the mean squared error on 20 points held out from training, the average squared gap between prediction and target. One stump alone scores 0.261.
  2. In bagging, each tree gets a bootstrap sample: 25 random draws with replacement, so some points repeat and others are left out (the hollow dots). Each tree fits its own sample, and the prediction is the average of all 20. No tree depends on another, so they can train in parallel. Averaging smooths out the quirks each tree picks up from its sample, and test error falls to 0.145. It cannot fix a mistake every tree shares. All 20 stumps split between x = −0.25 and 0.63, so their average stays a blunt step.
  3. Boosting starts from the average target and fits tree 1 to the residuals, each point's target minus the current prediction. It adds that tree scaled by 0.3, the learning rate, recomputes the residuals and fits tree 2 to what is left. Each tree needs the one before it, so they train in sequence. Each can split somewhere new, so the sum bends with the curve. After 20 trees the test error is 0.066.

Takeaway

Bagging mainly cuts variance, how much a model changes from one training sample to the next. Boosting mainly cuts bias, the error of a model too simple for the pattern. A stump has high bias and little variance, so boosting wins here. Bag 20 full-depth trees instead, grown until each fits its sample exactly, and test error falls from 0.068 for one tree to 0.055, below boosting's 0.066.

Go deeper · interactive

Gradient Boosting

On the Fit the Residuals step, press Play and compare each round's residuals with the stump fitted to them.

Open the explainer

More bites

References