Gradient Boosting
Gradient Boosting is an ensemble learning method that builds a strong predictive model by sequentially adding weak learners — typically shallow decision trees — each one trained to correct the residual errors of the combined ensemble so far. It is one of the dominant algorithms in structured/tabular data competitions and production ML systems, powering everything from click-through rate prediction at major tech companies to medical risk scoring. A counterintuitive fact: despite being called "gradient" boosting, the gradients being followed are in function space, not parameter space — the algorithm never takes a derivative with respect to any weight vector in the traditional sense.
Instead of fitting a model to labels directly, gradient boosting fits each new weak learner to the negative gradient of the loss function evaluated at the current ensemble's predictions. For squared-error loss this negative gradient is just the residual, but the genius is that this formulation generalises to any differentiable loss — log-loss, Huber loss, quantile loss — simply by swapping the gradient formula. The "aha moment" is recognising that gradient descent in function space and the classic residual-fitting intuition are the same algorithm viewed through different lenses.
How It Works
Setting Up the Functional Gradient Framework
Let the dataset be and let be a differentiable loss function. Gradient boosting constructs an additive model:
Explanation: The final model is a sum of weak learners , each scaled by a learning rate , added on top of a base prediction .
Symbols:
- — the full ensemble after boosting rounds
- — initial constant prediction (usually the minimiser of over constants, e.g. the mean for MSE)
- — the -th weak learner (typically a regression tree)
- — learning rate / shrinkage parameter
- — total number of boosting rounds
Computing Pseudo-Residuals
At each step , compute the pseudo-residuals — the negative gradient of the loss with respect to the current predictions:
Explanation: Each pseudo-residual is the direction in which we should nudge the prediction for example to reduce the loss most steeply.
Symbols:
- — pseudo-residual for sample at boosting round
- — loss for sample given prediction
- — partial derivative with respect to the prediction value (not a parameter)
Concrete example for MSE: , so — the ordinary residual.
For log-loss (binary classification): Let . Then:
Explanation: Even for classification, the pseudo-residual takes the same residual form, but here is a predicted probability, making this a probability-error signal rather than a raw output error.
Fitting and Line Search
Fit a weak learner to the pseudo-residuals . Then find an optimal step size by solving:
Explanation: This one-dimensional line search finds the scalar multiplier that most reduces the total loss when we add to the ensemble, analogous to choosing the right step size in gradient descent. Update the ensemble:
Explanation: The new ensemble is the old one plus the scaled, line-search-optimal new weak learner, shrunk further by to prevent overfitting. In practice — especially in XGBoost and LightGBM — the leaf-level step sizes are absorbed into the tree's leaf values, making a separate unnecessary; the tree fitting and line search happen simultaneously. ---
Friedman is a statistician at Stanford University who unified boosting as gradient descent in function space in his landmark 2001 paper "Greedy Function Approximation: A Gradient Boosting Machine." He also introduced stochastic gradient boosting — subsampling the training data at each round — which dramatically improved both speed and generalisation. Remarkably, Friedman developed much of this theory while simultaneously co-authoring The Elements of Statistical Learning, which became one of the most cited ML textbooks in history.
Breiman was a statistician at UC Berkeley best known for inventing Random Forests, but his 1997 paper "Arcing the Edge" was one of the first to interpret boosting as a gradient descent procedure, directly inspiring Friedman's later formalisation. His insight that ensemble methods could be understood through statistical optimisation lenses shifted the field's thinking away from purely algorithmic explanations. Breiman famously left academia for a decade to work as a consultant before returning to Berkeley — his practical experience strongly shaped his skepticism of overly parametric statistical models.
---
---
---
PyTorch / NumPy Implementation Sketch
```python import numpy as np from sklearn.tree import DecisionTreeRegressor class GradientBoostingMSE: """Minimal gradient boosting for regression (MSE loss).""" def __init__(self, n_estimators=100, learning_rate=0.1, max_depth=3): self.n_estimators = n_estimators self.lr = learning_rate self.max_depth = max_depth self.trees = [] self.F0 = None def fit(self, X, y):
# Initialise F0 as the mean (minimises MSE over constants) self.F0 = np.mean(y) F = np.full(len(y), self.F0) for m in range(self.n_estimators):
# [Eq 2] Pseudo-residuals = negative gradient of MSE = y - F residuals = y - F
# Fit a shallow tree to the pseudo-residuals tree = DecisionTreeRegressor(max_depth=self.max_depth) tree.fit(X, residuals) self.trees.append(tree)
# [Eq 5] Update ensemble F += self.lr tree.predict(X) return self def predict(self, X): F = np.full(X.shape[0], self.F0) for tree in self.trees: F += self.lr tree.predict(X) return F
# Quick validation on synthetic data rng = np.random.default_rng(42) X = rng.standard_normal((500, 5)) y = np.sin(X[:, 0]) + 0.5 X[:, 1] <strong> 2 + rng.standard_normal(500) 0.1 model = GradientBoostingMSE(n_estimators=200, learning_rate=0.05, max_depth=4) model.fit(X, y) preds = model.predict(X) print(f"Train MSE: {np.mean((y - preds)2):.4f}") ```
Intuition
Imagine you are a sculptor fixing a rough clay figure through committee critique. On day 1, a first apprentice makes the best figure they can. On day 2, a second apprentice looks only at where the first figure is still wrong — too tall here, too thin there — and makes a correction figure that captures just those errors. A third apprentice does the same for the remaining errors, and so on. The final sculpture is the sum of all the correction layers. The critical insight is that each apprentice is not trying to recreate the whole figure from scratch; they are only responsible for what the previous team got wrong. The "gradient" is just a mathematically precise answer to the question "which direction should the correction go?" — and choosing a good loss function is choosing a good definition of "wrong."
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
AdaBoost · Random Forests · Regularisation · Feature Importance and SHAP · Bayesian Optimisation