Gradient Boosting
Gradient Boosting — Fit each new tree to the residual errors of the last.
Gradient boosting builds an ensemble by having each new tree predict the residual errors left over by the current ensemble. Add them up with a small learning rate and the errors shrink round after round.
Residuals round 1 is about to fit — RMS 1.22
- Data
- Ensemble fit
- Stump before shrinkage
- Residuals
Boosting controls
The idea in plain words
Gradient boosting builds its ensemble by having each new tree predict the residual errors left over by the current model. Add that tree with a small learning rate, and the leftover error shrinks. Repeat, and the fit tightens round after round.
The red arrows are the residuals each new stump chases. Unlike AdaBoost’s reweighting, this is literally gradient descent in function space. Too high a learning rate with too many rounds overfits — test error starts to climb.
Now, the math
Each stage adds a shrunken tree fit to the current residuals:
- the m-th tree, fit to the residuals of the current ensemble.
- the learning rate (shrinkage) — small steps generalize better.
▸ Show the derivation
For squared-error loss the negative gradient at each point is exactly the residual y − F(x), so fitting a tree to the residuals is a gradient-descent step in function space. Shrinkage (small η) trades more rounds for better generalization; large η with many rounds memorizes the training noise.
Trace it by hand
Four points — (1, 1), (2, 2), (3, 5), (4, 6) — fit with depth-1 regression trees (stumps) and learning rate η = 0.5, exactly the algorithm the interactive runs. Every number below is exact.
Step 1 — start from the mean
The residuals y − F₀ are (−2.5, −1.5, 1.5, 2.5) — for squared error, exactly the negative gradient at each point.
Step 2 — fit stump h₁ to the residuals, then take a shrunken step
| x | y | F₀ | y − F₀ | h₁ | F₁ | y − F₁ |
|---|---|---|---|---|---|---|
| 1 | 1 | 3.5 | -2.5 | -2 | 2.5 | -1.5 |
| 2 | 2 | 3.5 | -1.5 | -2 | 2.5 | -0.5 |
| 3 | 5 | 3.5 | 1.5 | 2 | 4.5 | 0.5 |
| 4 | 6 | 3.5 | 2.5 | 2 | 4.5 | 1.5 |
The best split is x ≤ 2.5; the leaf values −2 and +2 are the residual means on each side. After the η = 0.5 step, every residual shrank by 1.
Step 3 — round 2 chases the new residuals
F₂ predicts (2, 2, 5, 5), leaving residuals (−1, 0, 0, 1). Two points are now fit exactly.
Step 4 — watch the error shrink
What just happened: no tree ever saw y directly — each one was fit purely to the previous ensemble’s leftover errors, and the η = 0.5 shrinkage meant each round only closed half the gap. The largest residual fell 2.5 → 1.5 → 1.0, which is gradient descent in function space, one small step per round.
Now Break It
Try this: A high learning rate with many rounds overshoots and overfits the training residuals.
Control: Learning rate slider (set high)
What happens: Overfitting the residuals! A high learning rate with many rounds memorizes noise.
Where gradient boosting is used
Gradient boosting is the reigning champion of tabular machine learning, and its optimized implementations, XGBoost, LightGBM, and CatBoost, dominate structured-data Kaggle competitions and power real production systems. It sits behind many search and ad ranking models via learning-to-rank objectives, credit-risk and fraud scoring where calibrated probabilities matter, demand forecasting, and click-through prediction. Its appeal is accuracy on heterogeneous features with support for custom loss functions, monotonic constraints, and native handling of missing values in the modern libraries. Because it fits each new tree to the errors the current ensemble still makes, gradient boosting keeps chipping away at bias, which is why a well-tuned booster usually edges out a random forest on the same tabular problem, at the cost of more careful tuning.
The main misconception is that gradient boosting fits each tree to the raw residuals. For squared-error loss that happens to be true, but in general each tree fits the negative gradient of the chosen loss function evaluated at the current predictions, which is what lets it target log-loss, quantile, or ranking objectives. A second pitfall is confusing it with bagging-based random forests: here trees are grown sequentially and are dependent, so they cannot be trained in parallel across the ensemble, and deeper individual trees make overfitting easier rather than safer. Control that with a small learning rate, shallow trees, subsampling of rows and columns, and early stopping on a validation set. Without regularization and enough rounds at a low learning rate, gradient boosting will happily memorize noise.
Frequently asked questions
What is gradient boosting?
Does gradient boosting really fit the residuals?
What is the difference between gradient boosting and random forests?
What does the learning rate do in gradient boosting?
How do I stop gradient boosting from overfitting?
Why is gradient boosting so popular on tabular data?
Written & reviewed by the ML Visualization team · Last updated .