Gradient Boosting

Derivation of boosting as functional gradient descent in function space: the additive model framework, residual fitting, gradient boosting for arbitrary differentiable losses, shrinkage, subsampling, and the XGBoost second-order formulation.

Advanced

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. Additive Models and Forward Stagewise Fitting
  5. Boosting as Functional Gradient Descent
  6. The Gradient Boosting Algorithm
  7. Gradient Boosting for Regression (Squared Loss)
  8. Gradient Boosting for Classification (Log-Loss)
  9. Regularization Techniques
  10. XGBoost: Second-Order Formulation
  11. Common Pitfalls
  12. Research Perspective
  13. Summary
  14. Exercises

Learning Objectives

  1. Formalize boosting as sequential minimization in function space.
  2. Derive the gradient boosting update as functional gradient descent.
  3. Show that for squared loss, gradient boosting fits residuals.
  4. Derive the XGBoost objective with second-order approximation.
  5. Explain the roles of shrinkage, subsampling, and tree depth in regularization.
  6. Compare the bias-reduction mechanism of boosting vs. the variance-reduction of bagging.

Notation

  • F(x)=m=0Mηhm(x)F(\mathbf{x}) = \sum_{m=0}^M \eta \cdot h_m(\mathbf{x}) — additive ensemble
  • hmh_mmm-th base learner (weak learner, typically a shallow tree)
  • η(0,1]\eta \in (0, 1] — learning rate (shrinkage)
  • L(y,F(x))L(y, F(\mathbf{x})) — loss function
  • y~i(m)=L(yi,F(xi))F(xi)F=Fm1\tilde{y}_i^{(m)} = -\frac{\partial L(y_i, F(\mathbf{x}_i))}{\partial F(\mathbf{x}_i)}\bigg|_{F=F_{m-1}} — pseudo-residuals
  • gi,hig_i, h_i — first and second derivatives of loss (XGBoost notation)

Core Intuition

While bagging reduces variance by averaging independent models, boosting reduces bias by sequentially correcting errors. Each new weak learner is fit to the mistakes (pseudo-residuals) of the current ensemble. The ensemble builds up a powerful predictor from many simple models, each contributing a small correction.

Gradient Boosting

Round 3
‖residual‖ = 0.464
Rounds
3
True f(x)EnsembleLatest tree
Explore: Each round fits a weak learner (stump) to the residuals. The ensemble (blue) gradually approaches the true function as residuals shrink.

Additive Models and Forward Stagewise Fitting

The ensemble model is additive:

FM(x)=F0(x)+m=1Mηhm(x),(1)F_M(\mathbf{x}) = F_0(\mathbf{x}) + \sum_{m=1}^M \eta \cdot h_m(\mathbf{x}), \tag{1}

where F0F_0 is a constant initialization (e.g., the mean of yy) and each hmh_m is a shallow tree.

Forward stagewise fitting: At step mm, fix all previous terms and optimize only hmh_m:

hm=argminhi=1nL(yi,Fm1(xi)+ηh(xi)).(2)h_m = \arg\min_h \sum_{i=1}^n L\bigl(y_i, F_{m-1}(\mathbf{x}_i) + \eta\cdot h(\mathbf{x}_i)\bigr). \tag{2}

Boosting as Functional Gradient Descent

View FF as a point in function space. The loss functional is L(F)=iL(yi,F(xi))\mathcal{L}(F) = \sum_i L(y_i, F(\mathbf{x}_i)). The functional gradient at data points is:

FLF=Fm1=[L(yi,F(xi))F(xi)]i=1n.(3)-\nabla_F\mathcal{L}\Big|_{F=F_{m-1}} = \left[-\frac{\partial L(y_i, F(\mathbf{x}_i))}{\partial F(\mathbf{x}_i)}\right]_{i=1}^n. \tag{3}

We cannot step directly in this infinite-dimensional direction, so we fit a base learner hmh_m to approximate the negative gradient:

hm=argminhi=1n(y~i(m)h(xi))2,(4)h_m = \arg\min_h \sum_{i=1}^n \bigl(\tilde{y}_i^{(m)} - h(\mathbf{x}_i)\bigr)^2, \tag{4}

where y~i(m)=LF(xi)Fm1\tilde{y}_i^{(m)} = -\frac{\partial L}{\partial F(\mathbf{x}_i)}\big|_{F_{m-1}} are the pseudo-residuals.


The Gradient Boosting Algorithm

  1. Initialize: F0(x)=argminciL(yi,c)F_0(\mathbf{x}) = \arg\min_c \sum_i L(y_i, c).
  2. For m=1,,Mm = 1, \ldots, M:
    • Compute pseudo-residuals: y~i(m)=L(yi,Fm1(xi))Fm1(xi)\tilde{y}_i^{(m)} = -\frac{\partial L(y_i, F_{m-1}(\mathbf{x}_i))}{\partial F_{m-1}(\mathbf{x}_i)}.
    • Fit base learner: hmargminhi(y~i(m)h(xi))2h_m \approx \arg\min_h \sum_i(\tilde{y}_i^{(m)} - h(\mathbf{x}_i))^2.
    • Update: Fm=Fm1+ηhmF_m = F_{m-1} + \eta \cdot h_m.
  3. Output: FM(x)F_M(\mathbf{x}).

Gradient Boosting for Regression (Squared Loss)

For L(y,F)=12(yF)2L(y, F) = \frac{1}{2}(y - F)^2:

y~i(m)=F12(yiF)2Fm1=yiFm1(xi).(5)\tilde{y}_i^{(m)} = -\frac{\partial}{\partial F}\frac{1}{2}(y_i - F)^2\bigg|_{F_{m-1}} = y_i - F_{m-1}(\mathbf{x}_i). \tag{5}

The pseudo-residuals are literally the residuals. Each tree fits the errors of the previous ensemble.


Gradient Boosting for Classification (Log-Loss)

For binary classification with L(y,F)=log(1+eyF)L(y, F) = \log(1 + e^{-yF}) where y{1,+1}y \in \{-1, +1\}:

y~i(m)=yi1+eyiFm1(xi).(6)\tilde{y}_i^{(m)} = \frac{y_i}{1 + e^{y_i F_{m-1}(\mathbf{x}_i)}}. \tag{6}

Points that are currently misclassified (large negative yiFm1y_iF_{m-1}) get pseudo-residuals close to ±1\pm 1 (high weight). Correctly classified points get small pseudo-residuals.


Regularization Techniques

Shrinkage (learning rate η\eta). Using η<1\eta < 1 scales each tree's contribution:

Fm=Fm1+ηhm,η(0.01,0.3).(7)F_m = F_{m-1} + \eta \cdot h_m, \quad \eta \in (0.01, 0.3). \tag{7}

Smaller η\eta requires more trees MM but generalizes better (analogous to smaller step size in optimization).

Subsampling (stochastic gradient boosting). Each tree is fit on a random fraction q(0.5,0.8)q \in (0.5, 0.8) of the training data. Introduces randomness similar to SGD.

Tree constraints: Limit depth (typically 3–8), minimum leaf size, and maximum leaves.

L2 regularization on leaf weights (in XGBoost): penalizes large predictions in individual leaves.


XGBoost: Second-Order Formulation

XGBoost uses a second-order Taylor approximation of the loss at step mm:

L(m)i=1n[gihm(xi)+12hihm(xi)2]+Ω(hm),(8)\mathcal{L}^{(m)} \approx \sum_{i=1}^n \left[g_i h_m(\mathbf{x}_i) + \frac{1}{2}h_i\cdot h_m(\mathbf{x}_i)^2\right] + \Omega(h_m), \tag{8}

where gi=L(yi,Fm1(xi))Fm1g_i = \frac{\partial L(y_i, F_{m-1}(\mathbf{x}_i))}{\partial F_{m-1}}, hi=2L(yi,Fm1(xi))Fm12h_i = \frac{\partial^2 L(y_i, F_{m-1}(\mathbf{x}_i))}{\partial F_{m-1}^2}, and Ω(hm)=γT+λ2j=1Twj2\Omega(h_m) = \gamma T + \frac{\lambda}{2}\sum_{j=1}^T w_j^2 penalizes tree complexity (TT = number of leaves, wjw_j = leaf weight).

Optimal leaf weight for leaf jj (containing indices IjI_j):

wj=iIjgiiIjhi+λ.(9)w_j^* = -\frac{\sum_{i \in I_j} g_i}{\sum_{i \in I_j} h_i + \lambda}. \tag{9}

Optimal objective value (used for split scoring):

L=12j=1T(iIjgi)2iIjhi+λ+γT.(10)\mathcal{L}^* = -\frac{1}{2}\sum_{j=1}^T \frac{(\sum_{i \in I_j}g_i)^2}{\sum_{i \in I_j}h_i + \lambda} + \gamma T. \tag{10}

Split gain: The reduction in objective from splitting leaf jj into L,RL, R:

Gain=12[(iILgi)2iILhi+λ+(iIRgi)2iIRhi+λ(iIjgi)2iIjhi+λ]γ.(11)\text{Gain} = \frac{1}{2}\left[\frac{(\sum_{i \in I_L}g_i)^2}{\sum_{i \in I_L}h_i + \lambda} + \frac{(\sum_{i \in I_R}g_i)^2}{\sum_{i \in I_R}h_i + \lambda} - \frac{(\sum_{i \in I_j}g_i)^2}{\sum_{i \in I_j}h_i + \lambda}\right] - \gamma. \tag{11}

Common Pitfalls

Pitfall 1. Overfitting with too many trees and high learning rate. Unlike random forests, gradient boosting can overfit as MM increases. Use early stopping based on validation loss.

Pitfall 2. Ignoring feature scale. While trees are scale-invariant, the pseudo-residuals and learning rate interact with the loss scale. Standardization is less critical than for linear models but still relevant for convergence speed.

Pitfall 3. Confusing bagging (reduces variance) with boosting (reduces bias). They attack different components of generalization error.


Research Perspective

Boosting was introduced by Schapire (1990) and Freund & Schapire (1995, AdaBoost). Friedman (2001) unified boosting as gradient descent in function space. XGBoost (Chen & Guestrin, 2016) added second-order optimization and systems-level efficiency, becoming the dominant method for tabular data. LightGBM (Ke et al., 2017) and CatBoost (Prokhorenkova et al., 2018) further improved scalability and handling of categorical features.


Summary

  • Gradient boosting builds additive models by sequentially fitting pseudo-residuals.
  • It is functional gradient descent: each tree approximates the negative gradient of the loss.
  • For squared loss, pseudo-residuals = actual residuals; for log-loss, they weight hard examples.
  • Shrinkage and subsampling prevent overfitting; early stopping is essential.
  • XGBoost uses a second-order Taylor expansion for optimal leaf weights and split scoring.
  • Boosting reduces bias (contrast with bagging which reduces variance).

Exercises

Exercise 1. Derive the pseudo-residuals for Huber loss L(y,F)={12(yF)2yFδδyFδ22otherwiseL(y,F) = \begin{cases}\frac{1}{2}(y-F)^2 & |y-F| \leq \delta \\ \delta|y-F| - \frac{\delta^2}{2} & \text{otherwise}\end{cases}.

Exercise 2. Show that AdaBoost is equivalent to forward stagewise fitting with exponential loss L(y,F)=eyFL(y,F) = e^{-yF}.

Exercise 3. Derive the optimal leaf weights (equation 9) by setting the derivative of the XGBoost objective to zero.

Exercise 4. Prove that gradient boosting with squared loss and depth-1 trees (stumps) is equivalent to fitting residuals with a single-split regressor.

Exercise 5. Explain mathematically why early stopping in gradient boosting acts as regularization (relate to the number of gradient descent steps).