Boosting
Add small models one after another, each focusing on the errors the previous ones left behind.
Lesson 46 of 6610 minIntermediate
You will learn to
- Explain sequential error correction
- Compare AdaBoost and gradient boosting
- Control boosting overfitting with learning rate and depth
Before this lesson
Intuition
Think of a student preparing for an exam with practice tests. After the first test, the student does not restudy everything. They look at the questions they got wrong and study those. After the next test, they focus on what is still wrong. Each round targets the remaining mistakes.
Boosting does this with models. It starts with a very simple model, often a tree only a few levels deep (a weak learner). Then it adds another small model whose job is to fix the errors of the current ensemble, then another, and so on. The final prediction is a weighted sum of all the small models.
This is the opposite of bagging. Bagging trains many models in parallel and averages out their variance. Boosting trains models in sequence, and mainly reduces bias: a single shallow tree is too simple, but a few hundred of them, each correcting the last, can model a complicated pattern.
There are two classic ways to say "focus on the mistakes":
- AdaBoost re-weights the training rows. Rows the ensemble gets wrong receive more weight, so the next model concentrates on them.
- Gradient boosting fits each new model to the residuals: the remaining errors of the current ensemble. More precisely, to the gradient of the loss, which for squared error is the residual.
Picture it
Round 1 makes one mistake, so that row grows in round 2. Round 2 places its cut to fix it and makes a different mistake, which grows in round 3. No single cut is good, but the combination is.
The math
Gradient boosting. Start from a constant prediction (the mean for squared error). At stage , fit a small tree to the residuals and add it with a small step , the learning rate:
A smaller means smaller, more cautious steps, so you need more stages but usually generalise better.
AdaBoost. With weights summing to 1, a weak classifier has weighted error . Its vote strength and the weight update are:
where the sign is plus for a misclassified row (its weight grows), minus for a correct one, and renormalises the weights to sum to 1. The final classifier is the sign of .
Worked example
AdaBoost, one round. Ten rows start with weight 0.1 each. The first weak classifier gets one row wrong, so .
- , and .
- The wrong row: 0.1 x 3 = 0.3. Each of the nine right rows: 0.1 / 3 = 0.0333.
- The sum is 0.3 + 9 x 0.0333 = 0.6, so divide by 0.6: the wrong row has weight 0.5, and each right row has 0.0556.
After one round, the single hard row carries half of the total weight. The next weak classifier is forced to get that row right.
Gradient boosting, two stages. Take three rows with targets 2, 4 and 12. Use the mean, 6, as the starting prediction and learning rate 0.5. To keep the arithmetic visible, assume each tree fits the residuals exactly (a real shallow tree cannot).
| Row | y | Stage 0 | Residual | Stage 1 | Residual | Stage 2 | Residual |
|---|---|---|---|---|---|---|---|
| 1 | 2 | 6 | -4 | 4 | -2 | 3 | -1 |
| 2 | 4 | 6 | -2 | 5 | -1 | 4.5 | -0.5 |
| 3 | 12 | 6 | 6 | 9 | 3 | 10.5 | 1.5 |
The squared error is 16 + 4 + 36 = 56 at stage 0, then 4 + 1 + 9 = 14, then 1 + 0.25 + 2.25 = 3.5. Each stage multiplies the error by . A smaller would shrink it more slowly: that is the slow, careful learning that protects against overfitting.
How mlflow does it
- On a model candidate, Improve then Ensemble with Boosting wraps that model as the base estimator and starts a new model in the same run. You can set the number of base estimators; Start boosting runs it.
- The catalog also contains boosting algorithms as models in their own right: AdaBoost (
ada) and gradient boosting for classification (gbc) and regression (gbr). Their key settings appear in the hyperparameter panel: the number of estimators, the learning rate and the tree depth. The help text for AdaBoost notes a trade-off between learning rate and number of estimators. - Gradient boosting offers a subsample fraction. A value below 1 trains each stage on a random part of the rows, which lowers variance and raises bias a little.
See Improve a model and the algorithms catalog.
Common mistakes
- Boosting noisy labels. Boosting keeps pushing on hard rows, and mislabelled rows are the hardest. Clean the target first or use a lower learning rate.
- Too many stages with a large learning rate. The ensemble starts fitting noise. Lower the learning rate, limit depth, and check validation scores as stages are added.
- Deep base trees. Boosting wants weak learners. Depth 3 to 6 is common for trees; very deep trees overfit quickly.
- Expecting parallel speed. Stages depend on each other, so training cannot simply be split across models the way bagging can.
- Comparing on training scores. A boosted model can reach near-perfect training scores. Judge it on cross-validated scores.
Try it in mlflow
Boost a model candidate
- Open Runs and open a finished classification run, then open a model candidate such as a decision tree.
- Click Improve, then Ensemble.
- Choose Boosting, keep the default number of base estimators, and click Start boosting.
- Compare the new model with the one it wraps on the leaderboard.