Simple Algorithm
Machine Learning · Convergence · 28 min

Gradient Boosting as Functional Gradient Descent

Any differentiable loss, shrinkage and stochastic boosting.

Boosting is gradient descent in a space of functions, with each step projected onto what a small tree can represent. Making that precise explains a great deal: why AdaBoost is a special case, how Newton steps enter, why boosting a smoother acts as a spectral filter whose bias falls exponentially, why small steps make boosting trace a path close to the lasso, and when stopping early makes it consistent.

What you’ll learn

  • Formulate boosting as functional gradient descent, and derive per-leaf line searches and the Newton (second-order) variant.
  • Derive the operator I−(I−νS)mI-(I-\nu S)^m of L2L_2-boosting a linear smoother, and its exact bias and variance.
  • Show that small-step boosting is steepest descent in the ℓ1\ell_1 geometry, and relate it to forward stagewise regression, the lasso path and the ℓ1\ell_1 maximum-margin vote.
  • State convergence and consistency results for boosting with early stopping, and explain the role of subsampling.

Gradient descent with a projection

Let C(F)=1n∑iℓ(yi,F(xi))C(F)=\frac1n\sum_i\ell\big(y_i,F(\mathbf x_i)\big) be the empirical risk of a function FF, with the empirical inner product ⟨F,G⟩n=1n∑iF(xi)G(xi)\langle F,G\rangle_n=\frac1n\sum_iF(\mathbf x_i)G(\mathbf x_i). Its gradient at FF is the vector g\mathbf g with gi=∂ℓ(yi,F)/∂Fg_i=\partial\ell(y_i,F)/\partial F at F=F(xi)F=F(\mathbf x_i). The steepest-descent direction −g-\mathbf g is defined only on the sample and is not a tree, so each round chooses the base function h∈Hh\in\mathcal H that best represents it, takes a step along hh, and repeats. Two choices of "best" are standard:

  • AnyBoost (Mason, Baxter, Bartlett & Frean, 2000): maximize the directional derivative, h=arg max⁡h∈H⟨−g,h⟩nh=\argmax_{h\in\mathcal H}\langle-\mathbf g,h\rangle_n, natural when H\mathcal H has normalized functions such as ±1\pm1 classifiers.
  • Gradient boosting (Friedman, 2001): fit hh to −g-\mathbf g by least squares, natural for regression trees, whose scale is free.

For ±1\pm1-valued hh the two agree, since ∑i(−gi−h(xi))2=∑igi2−2∑i(−gi)h(xi)+n\sum_i(-g_i-h(\mathbf x_i))^2=\sum_ig_i^2-2\sum_i(-g_i)h(\mathbf x_i)+n. Either way, a line search (or a small fixed step ν\nu) follows.

DerivationAnyBoost with the exponential loss is AdaBoost
  1. gi=−yie−yiF(xi)g_i=-y_ie^{-y_iF(\mathbf x_i)}

    For ℓ(y,F)=e−yF\ell(y,F)=e^{-yF} with y∈{−1,+1}y\in\{-1,+1\}, the gradient puts weight e−yiF(xi)e^{-y_iF(\mathbf x_i)} on each example:

  2. ⟨−g,h⟩n ∝ ∑iD(i) yih(xi)=1−2εD(h),D(i)∝e−yiF(xi)\langle-\mathbf g,h\rangle_n\ \propto\ \sum_iD(i)\,y_ih(\mathbf x_i)=1-2\varepsilon_D(h),\qquad D(i)\propto e^{-y_iF(\mathbf x_i)}

    Normalizing those weights into a distribution DD, the directional derivative is the edge under DD, so the best ±1\pm1 classifier is the one with the smallest weighted error:

  3. An exact line search along hh gives α=12ln⁡1−εε\alpha=\tfrac12\ln\frac{1-\varepsilon}{\varepsilon}, as derived in AdaBoost & the Exponential Loss. With the binomial deviance instead, the same recipe yields LogitBoost-style updates; with squared loss, residual fitting.

Per-leaf line search. A tree with leaves R1,…,RJR_1,\dots,R_J is h=∑jcj1Rjh=\sum_jc_j\mathbf 1_{R_j}, and the leaves are disjoint, so the loss after the step separates over leaves. Friedman's TreeBoost keeps the tree's partition from the least-squares fit and replaces its leaf values by JJ separate line searches, γj=arg min⁡γ∑xi∈Rjℓ(yi,F(xi)+γ)\gamma_j=\argmin_\gamma\sum_{\mathbf x_i\in R_j}\ell\big(y_i,F(\mathbf x_i)+\gamma\big): in effect, JJ coefficients per round instead of one.

DerivationNewton boosting: a second-order step
  1. ∑iℓ(yi,F(xi)+f(xi))≈∑i[ℓi+gif(xi)+12hif(xi)2]\sum_i\ell\big(y_i,F(\mathbf x_i)+f(\mathbf x_i)\big)\approx\sum_i\Big[\ell_i+g_if(\mathbf x_i)+\tfrac12h_if(\mathbf x_i)^2\Big]

    Expand the loss to second order around the current fit, with gig_i and hi=∂2ℓ/∂F2h_i=\partial^2\ell/\partial F^2 evaluated at F(xi)F(\mathbf x_i):

  2. =∑i12hi(f(xi)+gihi)2+const=\sum_i\tfrac12h_i\Big(f(\mathbf x_i)+\frac{g_i}{h_i}\Big)^2+\text{const}

    Complete the square. The step is a weighted least-squares fit of the targets −gi/hi-g_i/h_i with weights hih_i:

  3. γj=−∑xi∈Rjgi∑xi∈Rjhi\gamma_j=-\frac{\sum_{\mathbf x_i\in R_j}g_i}{\sum_{\mathbf x_i\in R_j}h_i}

    On a leaf, where ff is a constant γ\gamma, the minimizer is a Newton step; for log loss with y∈{0,1}y\in\{0,1\} it is ∑(yi−pi)/∑pi(1−pi)\sum(y_i-p_i)/\sum p_i(1-p_i):

Friedman's gradient boosting uses the second derivative only for the leaf values; Newton boosting also grows the tree on the weighted problem, as LogitBoost does (Friedman, Hastie & Tibshirani, 2000) and as XGBoost does with an added penalty (XGBoost, LightGBM & CatBoost). For squared loss, hi=1h_i=1 and the two coincide.

Check your understanding

For the squared loss 12(y−F)2\tfrac12(y-F)^2, how do gradient boosting and Newton boosting differ?

  1. Newton boosting converges in a single round
  2. Newton boosting fits the residuals divided by their variance
  3. Gradient boosting cannot use the squared loss
  4. They are identical: the second derivative is 1, so the Newton targets −gi/hi-g_i/h_i are the residuals and every weight is 1
Show the answer

D. They are identical: the second derivative is 1, so the Newton targets −gi/hi-g_i/h_i are the residuals and every weight is 1

With gi=F(xi)−yig_i=F(\mathbf x_i)-y_i and hi=1h_i=1, the weighted least-squares problem is the ordinary residual fit. The two methods differ only for losses with non-constant curvature, such as log loss, where the weights pi(1−pi)p_i(1-p_i) emphasize uncertain examples.

Boosting a linear smoother

Trees adapt their partition to the data, which makes exact analysis hard. Bühlmann & Yu (2003) analyzed L2L_2-boosting (squared loss) with a linear base learner instead: a smoother S∈Rn×nS\in\R^{n\times n} that maps responses to fitted values, y^=Sy\hat{\mathbf y}=S\mathbf y, such as a smoothing spline or a kernel smoother. The algorithm starts from F^0=Sy\hat F_0=S\mathbf y and repeatedly adds the smoothed residuals: F^m=F^m−1+S(y−F^m−1)\hat F_m=\hat F_{m-1}+S(\mathbf y-\hat F_{m-1}). With one extra step this is Tukey's "twicing".

DerivationThe boosting operator and its bias and variance
  1. y−F^m=(I−S)m+1y⟹F^m=Bmy,Bm=I−(I−S)m+1\mathbf y-\hat F_m=(I-S)^{m+1}\mathbf y\quad\Longrightarrow\quad\hat F_m=B_m\mathbf y,\qquad B_m=I-(I-S)^{m+1}

    Each round multiplies the residual vector by I−SI-S, so after mm rounds the fit is a fixed linear map of y\mathbf y (Bühlmann & Yu's Proposition 1):

  2. Bm=Udiag⁡(1−(1−λk)m+1)U⊤B_m=U\diag\big(1-(1-\lambda_k)^{m+1}\big)U^\top

    Let S=Udiag⁡(λk)U⊤S=U\diag(\lambda_k)U^\top be symmetric with eigenvalues 0<λk≤10<\lambda_k\le1, as for smoothing splines. Then BmB_m has the same eigenvectors and filters each direction (with shrinkage ν\nu, replace λk\lambda_k by νλk\nu\lambda_k):

  3. bias2=1n∑k=1n(1−λk)2m+2μk2,variance=σ2n∑k=1n(1−(1−λk)m+1)2\text{bias}^2=\frac1n\sum_{k=1}^n(1-\lambda_k)^{2m+2}\mu_k^2,\qquad\text{variance}=\frac{\sigma^2}n\sum_{k=1}^n\Big(1-(1-\lambda_k)^{m+1}\Big)^2

    With y=f+ε\mathbf y=\mathbf f+\boldsymbol\varepsilon, Cov⁡ε=σ2I\Cov\boldsymbol\varepsilon=\sigma^2I and μ=U⊤f\boldsymbol\mu=U^\top\mathbf f, the averaged squared bias and variance follow coordinate by coordinate (Proposition 3):

The filter 1−(1−νλk)m1-(1-\nu\lambda_k)^m belongs to the same family as ridge regression's dk2/(dk2+λ)d_k^2/(d_k^2+\lambda) and early-stopped gradient descent's 1−(1−ηdk2)t1-(1-\eta d_k^2)^t, where dkd_k are the singular values of the design matrix (Ridge Regression in Depth): strong directions are fitted early and weak ones late, and the number of rounds acts as the regularization parameter. For small ν\nu, 1−(1−νλ)m≈1−e−νmλ1-(1-\nu\lambda)^m\approx1-e^{-\nu m\lambda}, so the path depends on ν\nu and mm mainly through the product νm\nu m, the "time" of a gradient flow.

Predict before you look

A direction of the smoother has eigenvalue λ=0.2\lambda=0.2, and you boost with ν=0.5\nu=0.5. How many smoother fits MM until that direction is fitted to at least 90%, that is, until 1−(1−νλ)M≥0.91-(1-\nu\lambda)^M\ge0.9?

Show the answer

22 fits

Each fit keeps a fraction 1−νλ=0.91-\nu\lambda=0.9 of that direction's remaining residual, so we need 0.9M≤0.10.9^M\le0.1, that is M≥ln⁡0.1/ln⁡0.9≈21.9M\ge\ln0.1/\ln0.9\approx21.9: 22 fits. A direction with λ=0.02\lambda=0.02 would need 230. Weak directions, where the smoother distrusts the data, are fitted last, which is exactly why stopping early regularizes.

Small steps, the ℓ1 geometry and the lasso path

Strip boosting down to linear regression with the dictionary of single standardized predictors, and shrink the step to a tiny ε\varepsilon. The result is forward stagewise regression:

text
FORWARD_STAGEWISE(standardized X, centered y, step eps, rounds T)
  beta = 0;  r = y
  for t = 1..T:
      j = argmax_k |x_k . r|            # predictor most correlated with the residual
      s = sign(x_j . r)
      beta_j = beta_j + eps * s         # move that single coefficient a tiny step
      r = r - eps * s * x_j
  return beta

Boosting with squared loss, base learners ±xj\pm\mathbf x_j and shrinkage ε\varepsilon. Replace the columns by a dictionary of trees and it is ε\varepsilon-boosting.

DerivationSmall-step boosting is steepest descent in the ℓ1 geometry
  1. min⁡∥Δ∥1≤ε∇L(β)⊤Δ=−ε∥∇L(β)∥∞atΔ=−ε sign⁡(∂jL) ej,  j=arg max⁡k∣∂kL∣\min_{\norm{\Delta}_1\le\varepsilon}\nabla L(\boldsymbol\beta)^\top\Delta=-\varepsilon\norm{\nabla L(\boldsymbol\beta)}_\infty\quad\text{at}\quad\Delta=-\varepsilon\,\sign(\partial_jL)\,\mathbf e_j,\ \ j=\argmax_k\abs{\partial_kL}

    Among all steps Δ\Delta of ℓ1\ell_1 length ε\varepsilon, the one that decreases a differentiable LL fastest to first order minimizes a linear function over the ℓ1\ell_1 ball, and that happens at a vertex, a single coordinate:

  2. −∂L∂βj=xj⊤(y−Xβ)=xj⊤r-\frac{\partial L}{\partial\beta_j}=\mathbf x_j^\top(\mathbf y-X\boldsymbol\beta)=\mathbf x_j^\top\mathbf r

    For L(β)=12∥y−Xβ∥2L(\boldsymbol\beta)=\tfrac12\norm{\mathbf y-X\boldsymbol\beta}^2 with standardized columns, the negative partial derivative is the correlation with the residual, so the steepest ℓ1\ell_1 step is the forward-stagewise step:

  3. min⁡∥Δ∥2≤ε∇L(β)⊤ΔatΔ=−ε ∇L(β)∥∇L(β)∥2\min_{\norm{\Delta}_2\le\varepsilon}\nabla L(\boldsymbol\beta)^\top\Delta\quad\text{at}\quad\Delta=-\varepsilon\,\frac{\nabla L(\boldsymbol\beta)}{\norm{\nabla L(\boldsymbol\beta)}_2}

    Gradient descent is the same construction over the ℓ2\ell_2 ball, whose minimizer is the whole negative gradient. The norm that defines "steepest" is what separates the two paths:

Each stagewise step raises ∥β∥1\norm{\boldsymbol\beta}_1 by at most ε\varepsilon while lowering the loss as fast as possible, so the path roughly minimizes the loss at each ℓ1\ell_1 budget: the lasso problem in constrained form. Efron, Hastie, Johnstone & Tibshirani (2004) made this precise for squared loss: as ε→0\varepsilon\to0 the stagewise path is computed by a modification of their LARS algorithm, and it coincides with the lasso path in simple cases such as orthogonal predictors; in general the two paths can differ, though they are often close.

This links the two halves of boosting theory. The quantity in the display is exactly the minimum margin of a vote from Why Boosting Resists Overfitting, and running boosting longer with small steps corresponds to relaxing the ℓ1\ell_1 budget. It is the boosting counterpart of gradient descent's drift toward the ℓ2\ell_2 maximum-margin direction on separable logistic regression (The Implicit Bias of Gradient Descent): no penalty is written down, yet the optimizer's geometry decides which of the many zero-loss solutions it approaches.

Check your understanding

Forward stagewise regression with a tiny step moves one coefficient at a time and has no penalty term. Why does its coefficient path resemble the lasso's?

  1. Because it soft-thresholds every coefficient after each step
  2. Because each step is the steepest-descent step within a small ℓ1\ell_1 ball, so the loss falls as fast as possible per unit of ℓ1\ell_1 norm
  3. Because it minimizes ∥y−Xβ∥2+λ∥β∥1\norm{\mathbf y-X\boldsymbol\beta}^2+\lambda\norm{\boldsymbol\beta}_1 explicitly
  4. Because it works only with orthogonal predictors
Show the answer

B. Because each step is the steepest-descent step within a small ℓ1\ell_1 ball, so the loss falls as fast as possible per unit of ℓ1\ell_1 norm

A linear function on the ℓ1\ell_1 ball is minimized at a vertex, a single coordinate. Following those steps keeps the ℓ1\ell_1 norm as small as possible for the loss achieved so far, which is what the lasso path does in constrained form.

Convergence, consistency and stochastic boosting

Optimization. For convex losses, greedy boosting over the span of a dictionary drives the empirical loss to its infimum over that span, under suitable step-size rules (Zhang & Yu, 2005). On separable data with exponential-type losses the infimum is approached only as the coefficients diverge, which is why the direction, not the size, of the vote is the interesting object.

Statistics. Running to convergence overfits: L2L_2-boosting of a smoother interpolates the data (MSE→σ2\text{MSE}\to\sigma^2), and AdaBoost with noisy labels fits the noise. Consistency comes from stopping early. Zhang & Yu (2005) give early-stopping strategies under which boosting is consistent for i.i.d. samples, with bounds on the rates; Bühlmann & Yu (2003) obtain minimax rates for boosted splines; Bartlett & Traskin (2007) show AdaBoost is consistent when stopped after n1−ϵn^{1-\epsilon} rounds. In practice the stopping round is chosen on validation data.

Stochastic gradient boosting. Friedman (2002) fitted each tree, and its leaf values, on a random fraction η\eta of the rows drawn without replacement, and found that this improved accuracy as well as speed. Two readings help. The random subsets decorrelate successive trees and average out some of their noise, like bagging. And each round now follows a noisy estimate of the functional gradient, computed on a random subsample, like a mini-batch step of SGD. Subsampling also blunts, without removing, a subtle bias that comes from computing gradients on the same points the model was trained on (Prokhorenkova et al., 2018); XGBoost, LightGBM & CatBoost shows how ordered boosting removes it.

Key takeaways

  • Boosting is functional gradient descent: each round projects the negative gradient onto the base class, by maximizing ⟨−g,h⟩n\langle-\mathbf g,h\rangle_n (AnyBoost) or by a least-squares fit (gradient boosting), then steps along it; with the exponential loss this is AdaBoost.
  • Newton boosting fits −gi/hi-g_i/h_i with weights hih_i, and its leaf values are −∑gi/∑hi-\sum g_i/\sum h_i; for squared loss it coincides with gradient boosting.
  • L2L_2-boosting a linear smoother gives Bm=I−(I−S)m+1B_m=I-(I-S)^{m+1}: bias falls exponentially and variance grows by exponentially small amounts; with a spline learner and early stopping it attains the minimax rate and adapts to unknown smoothness.
  • Small steps make boosting steepest descent in the ℓ1\ell_1 geometry: forward stagewise regression tracks the lasso path, and on separable data the normalized vote approaches an ℓ1\ell_1 maximum-margin solution.
  • Boosting's loss converges to its infimum, but consistency needs early stopping; row subsampling (stochastic gradient boosting) adds speed and a bagging-like variance reduction.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

In AnyBoost with the exponential loss and ±1\pm1 base classifiers, which base classifier maximizes ⟨−g,h⟩n\langle-\mathbf g,h\rangle_n?

  1. The one with the smallest unweighted training error
  2. The one with the smallest error under weights proportional to e−yiF(xi)e^{-y_iF(\mathbf x_i)}
  3. The one most correlated with the current score FF
  4. The one that misclassifies the fewest points with positive margin
Show the answer

B. The one with the smallest error under weights proportional to e−yiF(xi)e^{-y_iF(\mathbf x_i)}

The gradient of e−yFe^{-yF} weights each example by e−yiF(xi)e^{-y_iF(\mathbf x_i)}, and the directional derivative equals the edge 1−2εD(h)1-2\varepsilon_D(h) under the normalized weights: AdaBoost's weak-learning step.

Question 2

The base learner is least squares on a fixed set of basis functions, so SS is a projection. What does L2L_2-boosting do after its first step?

  1. It converges to the interpolant of the data
  2. It doubles the fit at every step
  3. Nothing: the residuals are orthogonal to the basis, so every later fit is zero and Bm=SB_m=S
  4. It slowly adds the components outside the basis
Show the answer

C. Nothing: the residuals are orthogonal to the basis, so every later fit is zero and Bm=SB_m=S

After the first fit, y−Sy\mathbf y-S\mathbf y is orthogonal to the column space of SS, so S(y−Sy)=0S(\mathbf y-S\mathbf y)=0. Boosting needs a weak learner, one that shrinks (λk<1\lambda_k<1), to have anything to add.

Question 3

A leaf of a log-loss Newton step holds 5 examples, all currently predicted at p=0.2p=0.2, and 2 of them are positive (y=1y=1). What is the leaf value ∑(yi−pi)/∑pi(1−pi)\sum(y_i-p_i)/\sum p_i(1-p_i), in log-odds?

  1. 0.2
  2. 1.0
  3. 1.25
  4. 0.8
Show the answer

C. 1.25

∑(yi−pi)=2−5(0.2)=1\sum(y_i-p_i)=2-5(0.2)=1 and ∑pi(1−pi)=5(0.16)=0.8\sum p_i(1-p_i)=5(0.16)=0.8, so the step is 1.251.25. The log-odds move from ln⁡(0.2/0.8)≈−1.39\ln(0.2/0.8)\approx-1.39 to about −0.14-0.14, a probability near 0.47: one Newton step overshoots the leaf's empirical rate of 0.4, which an exact line search (γ≈0.98\gamma\approx0.98) would hit.

Question 4

On linearly separable data, gradient descent on the logistic loss of a linear model drifts toward the ℓ2\ell_2 maximum-margin direction. Toward what does small-step boosting over a dictionary of base classifiers drift?

  1. The same ℓ2\ell_2 maximum-margin direction
  2. The vote with the fewest base classifiers
  3. The minimum-norm interpolant
  4. An ℓ1\ell_1 maximum-margin vote, arg max⁡∥β∥1=1min⁡iyiβ⊤h(xi)\argmax_{\norm{\boldsymbol\beta}_1=1}\min_iy_i\boldsymbol\beta^\top\mathbf h(\mathbf x_i)
Show the answer

D. An ℓ1\ell_1 maximum-margin vote, arg max⁡∥β∥1=1min⁡iyiβ⊤h(xi)\argmax_{\norm{\boldsymbol\beta}_1=1}\min_iy_i\boldsymbol\beta^\top\mathbf h(\mathbf x_i)

Each small boosting step moves one coefficient, the steepest descent direction in the ℓ1\ell_1 geometry, and Rosset, Zhu & Hastie (2004) showed that boosting approximately follows the ℓ1\ell_1-regularized path, whose normalized limit on separable data maximizes the ℓ1\ell_1 margin. The geometry of the optimizer selects the solution.

Further reading

  • J. H. Friedman, "Greedy function approximation: a gradient boosting machine," Annals of Statistics 29(5), 1189–1232 (2001).
  • L. Mason, J. Baxter, P. Bartlett & M. Frean, "Boosting algorithms as gradient descent," Advances in Neural Information Processing Systems 12, 512–518 (2000).
  • P. Bühlmann & B. Yu, "Boosting with the L2 loss: regression and classification," Journal of the American Statistical Association 98(462), 324–339 (2003).
  • S. Rosset, J. Zhu & T. Hastie, "Boosting as a regularized path to a maximum margin classifier," Journal of Machine Learning Research 5, 941–973 (2004).
  • T. Zhang & B. Yu, "Boosting with early stopping: convergence and consistency," Annals of Statistics 33(4), 1538–1579 (2005).