Özer Cem KELAHMETKELAHMET
Tools · Machine learning

Gradient boosting

Gradient boosting builds an ensemble of small trees, each correcting the errors of the previous ones. Learn how it works and why it dominates tabular data.

Overview

Gradient boosting builds a strong model by adding many small decision trees one after another. The first tree makes a rough prediction. The second tree is trained to predict what the first got wrong. The third corrects what the first two still get wrong, and so on, for hundreds or thousands of rounds. The final prediction is the sum of all the trees, each scaled down by a small factor called the learning rate.

For classification and regression on tables of business data, such as customer records, transactions or sensor summaries, gradient-boosted decision trees (GBDT) have long been the method to beat. Libraries such as XGBoost, LightGBM and CatBoost made them fast, scalable and easy to use.

An everyday picture is a team of editors working on a document in turn. The first fixes the obvious problems. Each later editor reads only the remaining mistakes and fixes a few of them. No single editor is brilliant, but the document gets steadily better, and you stop when the corrections no longer improve it.

What it is

Part What it does
Base learner A small tree, often 3 to 8 levels deep or limited by leaf count
Loss function Measures error: squared error, log loss, ranking losses and others
Pseudo-residuals The negative gradient of the loss for each example
Learning rate (shrinkage) Scales each tree's contribution, typically 0.01 to 0.3
Number of rounds How many trees are added
Early stopping Stops adding trees when validation error stops improving
Subsampling Uses a random fraction of rows or columns per tree
Regularisation Penalties on leaf values and tree size

The word "gradient" is the key. For squared error, the pseudo-residuals are simply actual minus predicted values. For other losses, such as log loss in classification, they are the direction in which each prediction should move to reduce the loss fastest. Fitting trees to gradients lets one algorithm handle many kinds of problems.

Where it came from

Boosting began as a theoretical question in learning theory: can many weak learners, each only slightly better than guessing, be combined into a strong one? Yoav Freund and Robert Schapire's AdaBoost, published in journal form in 1997, answered yes in practice by reweighting examples that earlier learners got wrong.

Jerome Friedman's paper "Greedy Function Approximation: A Gradient Boosting Machine", published in the Annals of Statistics in 2001, reframed boosting as gradient descent in the space of functions. That gave a general recipe for any differentiable loss. Friedman's follow-up work added stochastic gradient boosting, where each tree sees a random subsample of rows.

The modern era came with engineering. XGBoost, described in a 2016 paper by Tianqi Chen and Carlos Guestrin, added second-order gradients, regularisation, sparse-data handling and fast parallel training. LightGBM, described in a 2017 paper from Microsoft researchers, used histogram-based splits and leaf-wise growth for speed. CatBoost, from Yandex, described in a 2018 paper, introduced ordered boosting and careful categorical encoding to avoid target leakage. scikit-learn also offers histogram-based gradient boosting estimators.

How it works

Step 1: start with a constant

The initial prediction is a single number, such as the mean of the target for regression or the log-odds of the positive class for classification.

Step 2: compute pseudo-residuals

For each training example, compute the negative gradient of the loss with respect to the current prediction. This tells you how, and how much, each prediction should change.

Step 3: fit a small tree to them

Train a shallow regression tree to predict those pseudo-residuals from the features. The tree groups examples that need similar corrections.

Step 4: set leaf values

Each leaf gets a correction value that best reduces the loss for the examples in it. XGBoost and LightGBM use both first and second derivatives here, with a penalty on large leaf values.

Step 5: add the tree, scaled down

Add the tree's output, multiplied by the learning rate, to the current predictions. A small learning rate means each tree changes little, which needs more rounds but usually generalises better.

Step 6: repeat and stop early

Repeat steps 2 to 5. After each round, measure the loss on a validation set and stop when it has not improved for a set number of rounds.

import lightgbm as lgb

model = lgb.LGBMClassifier(n_estimators=2000, learning_rate=0.05, num_leaves=31)
model.fit(X_train, y_train, eval_set=[(X_val, y_val)],
          callbacks=[lgb.early_stopping(100)])

Key concepts and terms

Term Meaning
GBDT Gradient-boosted decision trees
Weak learner A simple model only slightly better than chance
Shrinkage Another name for the learning rate
Pseudo-residual The negative gradient of the loss for one example
Early stopping Halting training when validation loss stops improving
Level-wise growth Expanding all nodes at one depth before going deeper
Leaf-wise growth Always splitting the leaf with the largest gain
Histogram binning Grouping feature values into bins to speed up split search
Column subsampling Using a random subset of features for each tree
Ordered boosting CatBoost's technique to avoid target leakage
Monotonic constraint Forcing a prediction to only rise, or only fall, with a feature

A worked example

This scenario is illustrative. An online lender wants to predict the probability that a loan defaults within 12 months. It has 200,000 past loans with 45 features and a 4 per cent default rate.

The team first fits logistic regression as a baseline: ROC AUC 0.74 on a time-based validation set of the most recent three months. It then trains LightGBM with learning rate 0.05, 31 leaves per tree, 80 per cent row and column subsampling, and early stopping after 100 rounds without improvement. Training stops at 640 trees, with validation AUC 0.81.

Because lending is regulated, the team adds a monotonic constraint so predicted risk can never fall as the debt-to-income ratio rises, which costs 0.003 AUC. It explains individual decisions with SHAP values and checks calibration, applying isotonic calibration on a separate slice. The model goes live in shadow mode first, scored alongside the existing system for a month before it is allowed to affect decisions.

Strengths and limitations

Strengths:

  • Usually among the most accurate methods for structured, tabular data.
  • Handles mixed feature types, missing values and non-linear interactions.
  • Flexible losses for regression, classification and ranking.
  • Mature, fast libraries with GPU support and good tooling.
  • Works well with explanation tools such as SHAP.

Limitations:

  • Many hyperparameters, which interact.
  • Sequential training makes each round depend on the last.
  • Can overfit small or noisy datasets without early stopping.
  • Cannot extrapolate beyond the range of training targets.
  • Less suited to raw images, audio and text, where deep learning dominates.

How it compares with alternatives

Method Accuracy on tables Tuning effort Notes
Gradient boosting Very high Medium to high The usual tabular benchmark
Random forest High Low Robust with defaults, trees built in parallel
Logistic regression Moderate Low Transparent baseline
TabPFN High on small tables Very low Pretrained tabular model, predicts in context
FT-Transformer Competitive High Deep learning for tables

Practical guidance and best practices

  1. Always use a separate validation set with early stopping.
  2. Start with a learning rate around 0.05 and let early stopping choose the number of trees.
  3. Tune tree size (depth or leaves) and minimum leaf size before other parameters.
  4. Use row and column subsampling for extra regularisation.
  5. Split validation data by time when the model will predict the future.
  6. Tune with a tool such as Optuna instead of large manual grids.
  7. Add monotonic constraints where domain knowledge demands them.
  8. Check calibration if probabilities feed into pricing or capacity decisions.

Common mistakes

  • Training without early stopping and letting the model memorise noise.
  • Target-encoding categories on the same rows used for training.
  • Tuning hyperparameters on the test set, then reporting the same test score.
  • Random splits on time-ordered data, which hides future leakage.
  • Expecting sensible predictions for inputs far outside the training range.
  • Trusting gain-based feature importance as a causal explanation.

Frequently asked questions

What is the difference between boosting and bagging?

Bagging, used by random forests, trains many trees independently on random samples and averages them, which mainly reduces variance. Boosting trains trees in sequence, each focused on the remaining errors, which mainly reduces bias. Boosting usually reaches higher accuracy but needs more care to avoid overfitting.

Which library should I choose?

All three major libraries are strong. LightGBM is often fastest on large datasets, CatBoost is convenient when there are many categorical features, and XGBoost is very widely supported. Try the one your platform supports best, then compare on your own validation data.

How many trees do I need?

There is no fixed number. It depends on the learning rate and the data. With a learning rate of 0.05, a few hundred to a few thousand trees is common. Let early stopping decide rather than guessing.

Does gradient boosting need feature scaling?

No. Trees split on thresholds, so scaling does not change the result. You still need sensible encoding of categories, unless the library handles them natively.

Can deep learning beat gradient boosting on tables?

Sometimes. Pretrained tabular models and specialised architectures have become competitive, especially on small datasets. On many medium and large tabular problems, well-tuned boosting remains a strong and cheap baseline.

Glossary

  • Boosting: combining weak learners in sequence so each fixes earlier errors.
  • Learning rate: the factor that scales each new tree's contribution.
  • Pseudo-residual: the gradient-based target each new tree is fitted to.
  • Early stopping: stopping when validation performance stops improving.
  • Base learner: the simple model added each round, usually a shallow tree.
  • Leaf-wise growth: splitting the most promising leaf first.
  • Subsampling: training each tree on a random fraction of rows or columns.
  • Monotonic constraint: a rule that keeps a feature's effect one-directional.

Summary

Gradient boosting adds small decision trees in sequence, each fitted to the gradient of the loss, so the ensemble steadily corrects its own errors. The idea runs from AdaBoost in 1997 through Friedman's gradient boosting machine in 2001 to the XGBoost, LightGBM and CatBoost libraries. It is usually the most accurate choice for tabular data, but it needs early stopping, honest validation and some tuning. Use it after a simple baseline, validate by time where relevant, and explain it with SHAP.

It belongs to ML foundations in my stack, under Machine learning. Others in the same group:

Type to search.
    ↑↓ navigate↵ open