Gradient boosting: learning rate, trees and early stopping

Updated

Gradient boosting builds a prediction as a sum of many small decision trees, each one fitted to the errors left by all the trees before it. A learning rate shrinks each tree's contribution so the model improves in small steps, and the number of trees is chosen where the error on held-out data stops falling. Tuned well, it is often the most accurate method for tabular process data; tuned badly, it memorizes the training data.

When to use it

  • You need the best prediction you can get from process data, for example to predict a lab result from in-line measurements before the lab reports it.
  • The effects are nonlinear and include interactions.
  • You have enough data to hold some back for validation, or to cross-validate.
  • You have already tried a simpler model and want to know how much accuracy is left on the table. See automated model comparison.

How it works

F₀(x) = ȳ For m = 1, 2, …, M: rᵢ = yᵢ − Fₘ₋₁(xᵢ) (current residuals) fit a small tree hₘ to the residuals rᵢ Fₘ(x) = Fₘ₋₁(x) + η · hₘ(x)

For squared-error loss, the residuals are the negative gradient of the loss with respect to the predictions, which gives the method its name. For a pass/fail outcome the same idea uses the log loss: each tree fits its gradient, and the model's output is a log-odds.

Four settings control the fit:

  • Learning rate η (shrinkage), usually 0.01 to 0.3. Small steps need more trees but usually generalize a little better.
  • Number of trees M. Too few and the model underfits; too many and it starts fitting noise. It is chosen by early stopping: track the error on validation data and keep the number of trees where it is lowest.
  • Tree depth. A tree of depth d can represent interactions among up to d inputs. Depths of 2 to 4 are typical.
  • Minimum leaf size, and optionally a random subsample of rows for each tree, both of which damp overfitting.

Example

The data are the same 200 molded parts used in the random forest article: warpage (mm) with five inputs, simulated with a known noise standard deviation of 0.08 mm. 150 parts, picked at random, are used for training and 50 are held out for validation. Trees have depth 2 and at least 5 parts per leaf.

One step by hand. The starting prediction is the training mean, F₀ = 1.279 mm. To see a single step, fit a one-split tree to the residuals: it splits cooling time at 14.9 s. The 33 parts with shorter cooling have an average residual of +0.327 mm and the other 117 have −0.092 mm. With η = 0.1, their predictions move to 1.279 + 0.0327 = 1.312 mm and 1.279 − 0.0092 = 1.270 mm. The next tree fits what is still left.

Learning rate and number of trees. Validation RMSE for four learning rates:

Learning rate10 trees50 trees100 trees200 trees500 treesBest (trees)
0.050.1960.1200.0960.0880.0870.0865 (358)
0.10.1670.0950.0870.0860.0920.0863 (181)
0.50.1020.0990.0990.1010.1010.0973 (65)
1.00.1090.1190.1210.1200.1200.0999 (6)

Predicting every validation part with the training mean gives an RMSE of 0.263 mm.

Validation error of gradient boosting by learning rate0.100.150.200.25Validation RMSE (mm)η = 0.05η = 0.1η = 0.5η = 1.015102550100200300500Number of trees
Validation error of gradient boosting by learning rate

With η = 0.1, the validation error bottoms out at 0.086 mm near 181 trees and then creeps up to 0.092 mm at 500, while the training error keeps falling, from 0.052 mm at 100 trees to 0.019 mm at 500. That gap is overfitting. η = 0.05 reaches the same minimum with about twice the trees and a flatter curve, so the exact stopping point matters less. η = 0.5 and 1.0 drop fast but stop at a worse error. The best result, 0.086 mm, is close to the 0.08 mm noise floor: little is left to find.

How to read the results

  • Read the validation curve, not the training curve. Training error always falls; validation error has a minimum.
  • A flat minimum is a good sign. It means the result does not hinge on the exact number of trees.
  • Compare with a baseline and with simpler models. Here the error fell from 0.263 to 0.086 mm, about a third.
  • Inputs are ranked the same way as in a forest, by permutation importance on held-out data.

Common mistakes

  • No early stopping. With 500 trees at η = 1.0 the training error is essentially zero and the validation error is 20% worse than its best.
  • Reporting the error from the data used to choose the number of trees. The minimum of a curve is slightly optimistic. Keep a separate test set, or nest the tuning inside cross-validation.
  • Random splits of time-ordered or repeated data. If the process drifts, validate on later data; if parts were measured several times, keep all measurements of a part on the same side.
  • Trusting predictions outside the data. Like any tree model, boosting predicts flat values beyond the range it saw.

Frequently asked questions

How is boosting different from a random forest?

A forest grows deep trees independently and averages them, which mainly reduces variance and needs little tuning. Boosting grows shallow trees in sequence, each correcting the last, which mainly reduces bias. On the same parts, cross-validated RMSE was 0.095 mm for boosting and 0.118 mm for a forest (see automated model comparison).

What learning rate should I start with?

0.05 to 0.1 is a common start. Lower it if you can afford more trees, and let early stopping choose their number.

How deep should the trees be?

Start with depth 2 or 3. Increase it only if validation error improves; deeper trees overfit faster.

Can gradient boosting handle pass/fail outcomes?

Yes. With log loss, the model predicts the log-odds of failing, which converts to a probability. Judge it by log loss or by how many failures it catches, not by plain accuracy.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab