Skip to content
nonconvexcard

Trees, Bagging and Boosting

Impurity and greedy splitting, the exact variance algebra behind bagging, and boosting derived as functional gradient descent.

Classical MLAdvanced⏱ 3 hours14 min readdecision treeentropyginibaggingrandom forest
5 problems →

Trees and impurity

A decision tree partitions X\Xcal by recursive axis-aligned splits and predicts a constant in each leaf. Growing it optimally is NP-hard, so the standard algorithm is greedy: at each node choose the split maximising the decrease in an impurity measure.

DefinitionImpurity measures

For a node with class distribution p=(p1,…,pC)p = (p_1,\dots,p_C):

entropy H(p)=−∑cpclog⁡pc,Gini G(p)=1−∑cpc2=∑cpc(1−pc),misclassification M(p)=1−max⁡cpc.\text{entropy } H(p) = -\sum_c p_c\log p_c, \qquad \text{Gini } G(p) = 1-\sum_cp_c^2 = \sum_c p_c(1-p_c), \qquad \text{misclassification } M(p) = 1-\max_cp_c .
PropositionConcave impurity gives non-negative information gain

Let Φ\Phi be concave on the probability simplex. A split of a node into children with weights wL+wR=1w_L+w_R=1 and distributions pL,pRp_L,p_R satisfying wLpL+wRpR=pw_Lp_L + w_Rp_R = p has

gain=Φ(p)−(wLΦ(pL)+wRΦ(pR))≥0,\text{gain} = \Phi(p) - \big(w_L\Phi(p_L) + w_R\Phi(p_R)\big) \ge 0 ,

with equality iff Φ\Phi is affine along the segment [pL,pR][p_L,p_R]. Entropy and Gini are strictly concave; misclassification error is concave but piecewise affine.

Key idea

This is why entropy and Gini are used and misclassification error is not, despite being the quantity we actually care about: because MM is piecewise affine, many splits have exactly zero gain under it, and the greedy algorithm has no signal to follow. A strictly concave surrogate always prefers a split that makes the children purer, even when it does not change the majority class in either. The choice of surrogate is driven by the optimisation, not by the statistics — the same pattern as the hinge and logistic losses standing in for the zero-one loss.

Bagging and random forests

PropositionBagging variance algebra

Let f^1,…,f^B\hat f_1,\dots,\hat f_B be predictors each with variance σ2\sigma^2 and pairwise correlation ρ\rho at a fixed input. The average fˉ=1B∑bf^b\bar f = \frac1B\sum_b\hat f_b has

Var⁡(fˉ)=ρσ2+1−ρBσ2→B→∞ρσ2.\Var(\bar f) = \rho\sigma^2 + \frac{1-\rho}{B}\sigma^2 \xrightarrow[B\to\infty]{} \rho\sigma^2 .

Key idea

The limit is ρσ2\rho\sigma^2, not 00. Averaging removes only the independent part of the variance; the correlated part survives no matter how many trees you grow. So after a few hundred trees, further averaging is wasted, and the only way to improve is to reduce ρ\rho.

That single observation is the entire design of random forests: in addition to bootstrap resampling (which decorrelates through the data), split on a random subset of m≪pm \ll p features at each node (which decorrelates through the algorithm). The cost is an increase in σ2\sigma^2 — each tree is worse — and the trade is favourable because the ρ\rho term dominates for large BB. Breiman's mm of p\sqrt p for classification is a tuning of exactly this trade.

AdaBoost

Algorithm — AdaBoost
  1. Initialise weights wi(1)=1/nw_i^{(1)} = 1/n.
  2. For t=1,…,Tt = 1,\dots,T:
  3. fit a weak classifier ht∈{±1}Xh_t\in\{\pm1\}^\Xcal minimising the weighted error εt=∑iwi(t)1{ht(xi)≠yi}\eps_t = \sum_i w_i^{(t)}\one\{h_t(x_i)\ne y_i\};
  4. set βt=12log⁡1−εtεt\beta_t = \tfrac12\log\dfrac{1-\eps_t}{\eps_t};
  5. reweight wi(t+1)∝wi(t)exp⁡(−βtyiht(xi))w_i^{(t+1)} \propto w_i^{(t)}\exp\big(-\beta_ty_ih_t(x_i)\big) and renormalise.
  6. Output FT(x)=∑t≤Tβtht(x)F_T(x) = \sum_{t\le T}\beta_th_t(x), classified by sign⁡FT\sign F_T.
TheoremAdaBoost is coordinate descent on the exponential loss

Consider minimising

E(F)=1n∑i=1nexp⁡(−yiF(xi))\mathcal{E}(F) = \frac1n\sum_{i=1}^n\exp\big(-y_iF(x_i)\big)

over additive models F=∑tβthtF = \sum_t\beta_th_t. Then at each round, the hh minimising E(Ft−1+βh)\mathcal{E}(F_{t-1}+\beta h) to first order in β\beta is the minimiser of the weighted error with weights wi(t)∝e−yiFt−1(xi)w_i^{(t)}\propto e^{-y_iF_{t-1}(x_i)}, and the exact minimising step size is βt=12log⁡1−εtεt\beta_t = \tfrac12\log\frac{1-\eps_t}{\eps_t}.

Key idea

AdaBoost was invented from a learning-theoretic question ("can weak learners be combined into a strong one?") and only later recognised as coordinate descent on the exponential loss. The recognition is what generalised it: once you know the algorithm is minimising a loss by greedy stagewise fitting, you can swap the loss, and gradient boosting is what you get.

TheoremAdaBoost drives training error to zero exponentially

If each weak learner satisfies εt≤12−γ\eps_t \le \tfrac12-\gamma for some γ>0\gamma>0, then the training error of FTF_T satisfies

1n∑i1{sign⁡FT(xi)≠yi}≤exp⁡(−2γ2T).\frac1n\sum_i\one\{\sign F_T(x_i)\ne y_i\} \le \exp\big(-2\gamma^2T\big) .

Gradient boosting

PropositionGradient boosting is gradient descent in function space

Let L(y,F)L(y,F) be differentiable in FF and consider minimising 1n∑iL(yi,F(xi))\frac1n\sum_iL(y_i,F(x_i)) over FF in the span of a base class B\mathcal{B}. Regard the objective as a function of the vector (F(x1),…,F(xn))∈Rn\big(F(x_1),\dots,F(x_n)\big)\in\R^n; its negative gradient has components

ri=−∂L(yi,F(xi))∂F(xi).r_i = -\frac{\partial L(y_i,F(x_i))}{\partial F(x_i)} .

Fitting ht∈Bh_t\in\mathcal{B} by least squares to (xi,ri)(x_i,r_i) and taking Ft=Ft−1+νβthtF_t = F_{t-1}+\nu\beta_th_t is a projected gradient step in this nn-dimensional space, with ν\nu the learning rate.

Reading the residuals for common losses:

Loss L(y,F)L(y,F)Negative gradient rir_i
12(y−F)2\tfrac12(y-F)^2yi−Fiy_i - F_i — the ordinary residual
log⁡(1+e−yF)\log(1+e^{-yF})yi σ(−yiFi)y_i\,\sigma(-y_iF_i) — residual weighted by uncertainty
e−yFe^{-yF}yie−yiFiy_ie^{-y_iF_i} — recovers AdaBoost
∣y−F∣\abs{y-F}sign⁡(yi−Fi)\sign(y_i-F_i) — robust, ignores outlier magnitude
Empirical observationBoosting resists overfitting longer than expected

Empirical observation — a regularity seen in experiments. No theorem on this page establishes it in general.

Boosted ensembles often continue to improve on test data long after the training error has reached zero, and adding hundreds more rounds frequently does not hurt.

What this does not say

The training-error theorem above says nothing about test error, and a naive capacity argument would predict severe overfitting: TT rounds of trees is a large hypothesis class. The partial explanation is margin theory: Schapire and co-authors showed that boosting continues to increase the margin distribution yiFT(xi)/∑tβty_iF_T(x_i)/\sum_t\beta_t after the training error hits zero, and there are margin-based generalisation bounds analogous to the SVM margin bound that are independent of TT.

This is a genuine explanation but not a complete one: the margin bounds are numerically loose, there are constructed examples where a larger minimum margin gives worse generalisation, and boosting with a very flexible base learner and noisy labels does overfit. The practical rules — shrinkage ν≈0.1\nu\approx0.1, shallow trees, early stopping on a validation set — are empirical, and gradient boosting remains the strongest method on tabular data for reasons that are not fully characterised.

Problems

Concave impurity gives non-negative information gainProof · Intermediate · 30 min The bagging variance formulaProof · Intermediate · 30 min AdaBoost as exact line search on the exponential lossProof · Advanced · 30 min AdaBoost drives training error to zero exponentiallyProof · Advanced · 1 hour Gradient boosting fits the negative functional gradientProof · Intermediate · 30 min

References

  • PaperLeo Breiman (1996). Bagging Predictors
  • PaperLeo Breiman (2001). Random Forests
  • PaperYoav Freund and Robert E. Schapire (1997). A Decision-Theoretic Generalization of On-Line Learning and an Application to Boosting
  • PaperJerome H. Friedman (2001). Greedy Function Approximation: A Gradient Boosting Machine
  • PaperTianqi Chen and Carlos Guestrin (2016). XGBoost: A Scalable Tree Boosting System

These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.

Results stated on this page

Problems (5)

All problems

Papers that use this mathematics