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 1Round 2Round 3Misclassified: its weight goes upCorrect
Three rounds of boosting on the same points. The dashed line is the split the round's weak model makes. A row it gets wrong (dark outline) is drawn larger, meaning heavier, in the next round.

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 F0F_0 (the mean for squared error). At stage mm, fit a small tree hmh_m to the residuals ri=yi−Fm−1(xi)r_i = y_i - F_{m-1}(x_i) and add it with a small step ν\nu, the learning rate:

Fm(x)=Fm−1(x)+ν hm(x)F_m(x) = F_{m-1}(x) + \nu\, h_m(x)

A smaller ν\nu means smaller, more cautious steps, so you need more stages but usually generalise better.

AdaBoost. With weights wiw_i summing to 1, a weak classifier has weighted error ε\varepsilon. Its vote strength and the weight update are:

α=12ln⁡1−εε,wi←wi e∓αZ\alpha = \tfrac{1}{2}\ln\frac{1-\varepsilon}{\varepsilon}, \qquad w_i \leftarrow \frac{w_i\, e^{\mp\alpha}}{Z}

where the sign is plus for a misclassified row (its weight grows), minus for a correct one, and ZZ renormalises the weights to sum to 1. The final classifier is the sign of ∑mαmhm(x)\sum_m \alpha_m h_m(x).

Worked example

AdaBoost, one round. Ten rows start with weight 0.1 each. The first weak classifier gets one row wrong, so ε=0.1\varepsilon = 0.1.

  • α=12ln⁡(0.9/0.1)=12ln⁡9=1.099\alpha = \tfrac12 \ln(0.9/0.1) = \tfrac12 \ln 9 = 1.099, and eα=3e^{\alpha} = 3.
  • 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).

RowyStage 0ResidualStage 1ResidualStage 2Residual
126-44-23-1
246-25-14.5-0.5
312669310.51.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 (1−ν)2=0.25(1-\nu)^2 = 0.25. A smaller ν\nu 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

  1. Open Runs and open a finished classification run, then open a model candidate such as a decision tree.
  2. Click Improve, then Ensemble.
  3. Choose Boosting, keep the default number of base estimators, and click Start boosting.
  4. Compare the new model with the one it wraps on the leaderboard.
Open in mlflow

Read in the docs

Check your understanding

  1. 1. How does boosting differ from bagging?
  2. 2. In AdaBoost, what happens to a training row that the current model classifies wrongly?
  3. 3. Your boosted model scores 99% on training folds and much lower on validation folds. Which change is most likely to help?