Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Boosting

Boosting
Combines many weak classifiers (that are slightly better than random guessing) to produce one powerful committee.
  • Weak classifiers included in the final model do not have equal weights.

G(x)=sign⁡ ⁣(∑m=1Mam Gm(x)),G(x) = \operatorname{sign}\!\left(\sum_{m=1}^{M} a_m \, G_m(x)\right),
Gm(x)= a weak learner, am= weightsG_m(x) = \text{ a weak learner, } a_m = \text{ weights}

AdaBoost

  • Adaboost is one of the first boosting model with binary targets, (−1,1)(-1,1).

  • Fit a weak classifier, Gm(x)G_m(x) on weighted data, then increase weights on misclassified points so that the next round focuses on them.

Process

  1. Initailize weights, wi=1N,i=1,...Nw_i=\frac{1}{N}, i=1, ...N

  2. For m1m_1 to MM:
    a. Fit a classifier Gm(x)G_m(x) to the training data using weights wiw_i.
    b. Compute

    errm  =  ∑i=1Nwi I ⁣(yi≠Gm(xi))∑i=1Nwi\mathrm{err}_m \;=\; \frac{\sum_{i=1}^{N} w_i \, I\!\big(y_i \neq G_m(x_i)\big)}{\sum_{i=1}^{N} w_i}
  • This is the weighted fraction of incorrectly classified observations.

    c. Compute

    αm  =  log⁡ ⁣(1−errmerrm)\alpha_m \;=\; \log\!\left(\frac{1-\mathrm{err}_m}{\mathrm{err}_m}\right)

    d. Set

    wi←wiexp⁡ ⁣[αm I ⁣(yi≠Gm(xi))]w_i \leftarrow w_i \exp\!\left[\alpha_m \, I\!\big(y_i \neq G_m(x_i)\big)\right]
  1. Final classification:

    G(x)  =  sign⁡ ⁣(∑m=1Mαm Gm(x))G(x) \;=\; \operatorname{sign}\!\left(\sum_{m=1}^{M} \alpha_m \, G_m(x)\right)
  • If classification is done correctly, the weight of an observation does not change.

  • If classification is done incorrectly, the weight is increased by multiplying with exp⁡(αm)\exp{(\alpha_m)}.

    • α\alpha varies with the degree of misclassification.

    • α\alpha is large if the error is small.

Normalizing the observation weights

After the example’s update, four observations have weight 1/61/6 and two have weight 1/31/3. Their total is 4/34/3. Dividing by this total gives weights 1/81/8 for each correct observation and 1/41/4 for each incorrect observation. The two mistakes now carry half the total weight.

Only relative weights matter when the next weighted error divides by their sum. Under normalization, correctly classified observations lose relative weight even though their unnormalized weights were unchanged.

For 0<errm<1/20<\mathrm{err}_m<1/2, the learner gets a positive vote. At 1/21/2 its vote is zero. A zero error requires a stopping rule because the log ratio diverges. Repeatedly upweighting mistakes can also focus on mislabeled observations; boosting does not automatically distinguish label noise from a difficult but useful case.

Forward Stagewise Additive Modeling

f(x)=∑m=1Mβmb(x;γm),f(x) = \sum^M_{m=1}\beta_mb(x;\gamma_m),
b( )= base functions of weak learners, γ= a parameter that tunes the basis function.b(\space) = \text{ base functions of weak learners, } \gamma = \text{ a parameter that tunes the basis function.}
  • Generally, boosting fits an additive model. Unlike Adaboost, it is not limited to 2-class classification.

  • The formula above is a re-written Adaboost classifier.

Estimation

  • A loss function has to be minimized:

min⁡{βm,γm}1M∑i=1NL(yi,∑m=1Mβmb(x;γm)),\min_{\{\beta_m, \gamma_m\}_1^M} \sum_{i=1}^{N} L\left(y_i, \sum_{m=1}^{M} \beta_m b(x; \gamma_m)\right),
L= loss functionL = \text{ loss function}
  • For example, if we set squared error loss as the loss function,

    min⁡{βm,γm}1M∑i=1N(yi−∑m=1Mβmb(x;γm))2\min_{\{\beta_m, \gamma_m\}_1^M} \sum_{i=1}^{N} \left(y_i - \sum_{m=1}^{M} \beta_m b(x; \gamma_m)\right)^2
  • In each iteration, we find the best fit to the residual from the previous iteration.

Loss Function
How wrong are we to predict fm−1(xi)+βmb(xi;γm)f_{m-1}(x_i) + \beta_m b(x_i;\gamma_m) when the truth is yiy_i?

MART Process

  1. Initialize f0(x)=0f_0(x) = 0

  2. For m=1m=1 to MM (total number of iterations),
    Add to the existing model such that the loss function is minimized.

    a. Minimize the loss ∑i=1NL[yi,fm−1(xi)+βmb(xi;γm)]\sum^{N}_{i=1}L[y_i, f_{m-1}(x_i) + \beta_mb(x_i;\gamma_m)].
    b. Update the function fm=fm−1(x)+βmb(x;γm)f_m = f_{m-1}(x) + \beta_mb(x;\gamma_m).

  • b(x;γm)b(x;\gamma_m): The new weak learner fitted this round.

  • βm\beta_m: Learning rate or step size for mm.

  • γm\gamma_m: The parameters of the new weak learner.

Logit Boost

Logit Boost
A boosting algorithm that uses deviance (log likelihood) as the loss function instead of the exponential loss used in AdaBoost. Outputs a probability between 0,10, 1 instead of class labels as in AdaBoost.
  • Forward stagewise algoirthm requires an estimate fm−1(xi)f_{m-1}(x_i).

  • Loss function used is the deviance (negative binomial likelihood).

    log⁡L=∑i=1N[yilog⁡pi+(1−yi)log⁡(1−pi)]\log L = \sum_{i=1}^{N} \left[ y_i \log p_i + (1 - y_i) \log(1 - p_i) \right]
  • First, derive pp as an expression of f(x)f(x).

log⁡(p1−p)=f(x)p1−p=ef(x)p=(1−p)ef(x)p=ef(x)−pef(x)p+pef(x)=ef(x)p(1+ef(x))=ef(x)p=ef(x)1+ef(x)\begin{aligned} \log\left(\frac{p}{1-p}\right) &= f(x) \\ \frac{p}{1-p} &= e^{f(x)} \\ p &= (1-p)e^{f(x)} \\ p &= e^{f(x)} - p e^{f(x)} \\ p + p e^{f(x)} &= e^{f(x)} \\ p(1 + e^{f(x)}) &= e^{f(x)} \\ p &= \frac{e^{f(x)}}{1 + e^{f(x)}} \end{aligned}
  • Rewrite the log likelihood:

p=ef(x)1+ef(x)ℓ(y)∝∑i=1n[yilog⁡(pi)+(1−yi)log⁡(1−pi)]=∑i=1n[yif(xi)−yilog⁡ ⁣(1+ef(xi))+(1−yi)log⁡ ⁣(11+ef(xi))]=∑i=1n[yif(xi)−log⁡ ⁣(1+ef(xi))]\begin{aligned} p &= \frac{e^{f(x)}}{1 + e^{f(x)}} \\ \ell(y) &\propto \sum_{i=1}^{n} \left[y_i \log(p_i) + (1-y_i)\log(1-p_i)\right] \\ &= \sum_{i=1}^{n} \Bigg[ y_i f(x_i) - y_i \log\!\big(1+e^{f(x_i)}\big) + (1-y_i)\log\!\left(\frac{1}{1+e^{f(x_i)}}\right) \Bigg] \\ &= \sum_{i=1}^{n} \Big[ y_i f(x_i) - \log\!\big(1+e^{f(x_i)}\big) \Big] \end{aligned}
  • yy is coded as 0,10,1.

  • Ultimately,

    fm∼fm−1(xi)+βmb(xi;γm)f_m \sim f_{m-1}(x_i)+\beta_mb(x_i;\gamma_m)

MART

Multiple Additive Regression Trees
Gradient boosting where weak learners are decision trees specifically.
βmb(xi;γm)=fm(xi)−fm−1(xi)\beta_mb(x_i;\gamma_m) = f_m(x_i) - f_{m-1}(x_i)

Assuming that trees (b(xi;γm)b(x_i;\gamma_m)) are being used as weak learners,

  1. Initialize f0f_0

  2. Fir m1m_1 to MM:
    a. Compute pseudo residuals.
    b. Fit a regression tree (with JJ terminal nodes) to pseudo residuals.
    c. For each terminal node, compute fitted values.
    d. Update fm=fm−1+ fitted valuesf_m=f_{m-1} + \text{ fitted values}.

  3. Output fmf_m as estimate of ff.

  • Loss function is minimized by going in the opposite direction of the gradient.

    rim=−[−∂l(yi,f(xi))∂f(xi)]f=fm−1r_{im} = -\left[-\frac{\partial l(y_i, f(x_i))}{\partial f(x_i)}\right]_{f = f_{m-1}}

Residuals depend on the loss

For loss L(y,f)L(y,f), the pseudo-residual is

rim=−∂L(yi,f)∂f∣f=fm−1(xi).r_{im}=-\left.\frac{\partial L(y_i,f)}{\partial f}\right|_{f=f_{m-1}(x_i)}.

With half-squared error, L=(y−f)2/2L=(y-f)^2/2, this is the ordinary residual y−fy-f. With binary log loss and ff measured in log-odds, it is y−py-p. The new tree is a regression tree fitted to these numerical residuals even when the original target is a class label.

The example uses residuals to choose regions, then a Newton approximation for each region’s update:

γjm=∑i∈Rjm(yi−pi)∑i∈Rjmpi(1−pi).\gamma_{jm}=\frac{\sum_{i\in R_{jm}}(y_i-p_i)}{\sum_{i\in R_{jm}}p_i(1-p_i)}.

This combines the first derivative with the curvature of the loss. Classical LogitBoost uses a weighted least-squares Newton procedure; the residual-tree construction here describes gradient tree boosting with Newton leaf updates.

Learning rate and stopping

Shrink the update by a learning rate 0<η≤10<\eta\leq1:

fm(x)=fm−1(x)+η∑jγjmI(x∈Rjm).f_m(x)=f_{m-1}(x)+\eta\sum_j\gamma_{jm}I(x\in R_{jm}).

A smaller η\eta takes smaller steps and generally needs more trees. Tune the learning rate, tree size, and number of rounds together. Early stopping selects the number of rounds using validation loss. The test set should not decide when to stop.

Usage

  • Data with nonlinear relationships.

  • Mixed type features.

  • Can fit difficult observations, but response outliers and label noise need care, especially with AdaBoost.

  • Need to look at the feature importance.

Limitations

  • Not quite interpretable

  • Data is extremely high-dimensional and sparse.

  • When a fast prediction is wanted.

    • Boosted-tree prediction can be slow because it evaluates many trees.

  • Time series and ordered data without careful splitting.

XGBoost

XGBoost
Optimized and extended implementation of gradient boosting. Uses both first and second derivatives.

Process

  1. Initialize a constant score appropriate to the loss. For binary log loss, probability 0.5 corresponds to log-odds score 0.

  2. Same as regular MART until fitting a tree with JJ leaves. Fit a regularized tree with a specifieid depth and allows for pruning.

  3. Fitted values are computed differently because of the regularization.

[∑i=1nl ⁣(yi; fm−1(xi)+γim)]+0.5 ν∑j=1Tγjm2+αT\left[ \sum_{i=1}^{n} l\!\left(y_i;\, f_{m-1}(x_i) + \gamma_{im}\right) \right] + 0.5\,\nu \sum_{j=1}^{T} \gamma_{jm}^{2} + \alpha T
SymbolMeaning
llLoss function.
γ2\gamma^2Squared (L2) penalty that discourages large leaf weights, similar to ridge regularization.
α\alphaComplexity penalty that encourages pruning (fewer leaves). It affects whether a split is accepted, but not the estimation of γ\gamma for a fixed tree.

Taylor Series

Taylor Series
A way to approximate a function using a polynomial built from the function’s derivates at a point.
  • If ff is analytic and xx lies within the convergence interval, then f(x)=∑n=0∞f(n)(a)n!(x−a)nf(x)=\sum_{n=0}^{\infty}\frac{f^{(n)}(a)}{n!}(x-a)^n.

    • A finite-order Taylor approximation needs suitable derivatives and a remainder term; infinitely many derivatives alone do not guarantee that the infinite series equals the function.

1st Order Approximation

In order to start approximating, the function ff needs to be differentiable at or near aa.

f(x)≈f(a)+f′(a)(x−a)f(x) \approx f(a) + f'(a)(x-a)
2nd Order Approximation

In order to continue with approximation, f(a)f(a) needs to exist (twice differentiable near aa).

f(x)≈f(a)+f′(a)(x−a)+f′′(a)2(x−a)2f(x) \approx f(a) + f'(a)(x-a) + \frac{f''(a)}{2}(x-a)^2

Loss Approximation with Taylor Series

Second order Taylor series expansion of the first term in regards to ∑i=1nl ⁣(yi; fm−1(xi)+γim)\sum_{i=1}^{n} l\!\left(y_i;\, f_{m-1}(x_i) + \gamma_{im}\right):

l(y,fm−1(xi)+γim)≈l(y,fm−1(xi))+γimgi+0.5hiγim2l(y, f_{m-1}(x_i) + \gamma_{im}) \approx l(y, f_{m-1}(x_i)) + \gamma_{im} g_i + 0.5 h_i \gamma_{im}^2

This approximates the loss for one observation. Sum over observations and add the regularization terms to obtain the objective.

SymbolMeaning
gig_iFirst derivative of the loss function with respect to fm−1(xi)f_{m-1}(x_i).
hih_iSecond derivatives.
∑i=1nl(yi,fm−1(xi))⏟current loss (constant)+∑i=1nγimgi+0.5∑i=1nhiγim2⏟Taylor expansion of loss+0.5ν∑j=1Tγjm2⏟L2 regularization on leaf weights+αT⏟penalty on number of leaves\underbrace{\sum_{i=1}^{n} l(y_i, f_{m-1}(x_i))}_{\text{current loss (constant)}} + \underbrace{\sum_{i=1}^{n}\gamma_{im}g_i + 0.5\sum_{i=1}^{n}h_i\gamma_{im}^2}_{\text{Taylor expansion of loss}} + \underbrace{0.5\nu\sum_{j=1}^{T}\gamma_{jm}^2}_{\text{L2 regularization on leaf weights}} + \underbrace{\alpha T}_{\text{penalty on number of leaves}}
∑i=1nl(yi,fm−1(xi))+∑j=1T[∑xi∈Rjmγimgi+0.5(∑xi∈Rjmhi+ν)γim2]+αT\sum_{i=1}^{n} l(y_i, f_{m-1}(x_i)) + \sum_{j=1}^{T}\left[\sum_{x_i \in R_{jm}} \gamma_{im}g_i + 0.5\left(\sum_{x_i \in R_{jm}} h_i + \nu\right)\gamma_{im}^2\right] + \alpha T
∂∂γim:∑xi∈Rjmgi+(∑xi∈Rjmhi+ν)γim=0\frac{\partial}{\partial \gamma_{im}}: \quad \sum_{x_i \in R_{jm}} g_i + \left(\sum_{x_i \in R_{jm}} h_i + \nu\right)\gamma_{im} = 0
γim=−∑xi∈Rjmgi∑xi∈Rjmhi+ν\gamma_{im} = -\frac{\sum_{x_i \in R_{jm}} g_i}{\sum_{x_i \in R_{jm}} h_i + \nu}
γim=∑xi∈Rjm(yi−fm−1(xi))njm+ν=sum of residualsnumber of residuals+ν\gamma_{im} = \frac{\sum_{x_i \in R_{jm}} (y_i - f_{m-1}(x_i))}{n_{jm} + \nu} = \frac{\text{sum of residuals}}{\text{number of residuals} + \nu}

Gaussian Outcomes

  • XGBoost is a generalization of standard gradient boosting.

  • Gaussian outcomes lead to a squared loss function.

  • Any proposed split splits one terminal node into two child nodes.

  • To evaluate the proposed split, we concentrate on the parent and child nodes only.

    similarity=sum of residuals2number of residuals+v\text{similarity}= \frac{\text{sum of residuals}^2}{\text{number of residuals} + v}
−∑i=1nl  +  12(similarityother+similarityparent)  −  αT-\sum_{i=1}^{n} l \;+\; \frac12\left(\mathrm{similarity}_{\text{other}} + \mathrm{similarity}_{\text{parent}}\right) \;-\; \alpha T

After split:

−∑i=1nl  +  12(similarityother+similarityleft+similarityright)  −  α(T+1)-\sum_{i=1}^{n} l \;+\; \frac12\left(\mathrm{similarity}_{\text{other}} + \mathrm{similarity}_{\text{left}} + \mathrm{similarity}_{\text{right}}\right) \;-\; \alpha (T+1)

The Gain (Difference):

gain⁡=12(similarityleft+similarityright−similarityparent)−α\operatorname{gain} = \frac12\left(\mathrm{similarity}_{\text{left}} + \mathrm{similarity}_{\text{right}} - \mathrm{similarity}_{\text{parent}}\right) - \alpha

Split gain from the regularized objective

Using the notation above, let Gj=∑i∈RjgiG_j=\sum_{i\in R_j}g_i and Hj=∑i∈RjhiH_j=\sum_{i\in R_j}h_i. The part depending on leaf weight γj\gamma_j is

Gjγj+12(Hj+ν)γj2+α.G_j\gamma_j+\frac12(H_j+\nu)\gamma_j^2+\alpha.

Its minimum occurs at γj=−Gj/(Hj+ν)\gamma_j=-G_j/(H_j+\nu). Substitution gives the split gain

12[GL2HL+ν+GR2HR+ν−GP2HP+ν]−α.\frac12\left[\frac{G_L^2}{H_L+\nu}+\frac{G_R^2}{H_R+\nu}-\frac{G_P^2}{H_P+\nu}\right]-\alpha.

The factor 1/21/2 follows from the objective written above. Omitting it requires rescaling the complexity penalty as well. The leaf penalty does not change the ranking of candidate splits that all add one leaf, but it does change whether a split is worth keeping.

For half-squared loss, gi=fi−yig_i=f_i-y_i and hi=1h_i=1, giving the residual formula above. For binary log loss on a log-odds score, gi=pi−yig_i=p_i-y_i and hi=pi(1−pi)h_i=p_i(1-p_i). The residual-count formula cannot be reused unchanged for binary classification.

Pruning

  • α\alpha does not affect finding out wich split has the highest gain.

  • Build a tree until some stopping criteria has been reached (e.g., maximum depth), and then prune all leaves from the bottom that have a negative α\alpha-adjusted gain.

    • This is equivalent to pruning all leaves with a gain less than a threshold α\alpha; a raw gain below α\alpha is rejected; an already penalty-adjusted gain is compared with 0.

Engineering Improvements

Fewer Split Points

  • To determine the best split for a given tree, we need to check every threhold for every variable. (e.g., If 1000 observations, 999 potential splits). This takes a long time. Instead, consider for each variable only quantiles.

Default Missing Value

  • If there is a missing value, find the split on that xx-variable as usual on non-missing values.

  • Evaluate gain in two options: Add missing values (with non-missing yy) to the left or the right child node.

  • Add missing values to the option leading to the greater gain.

  • This is mentioned as sparsity awareness.

Usage

When do we use XGBoost, not standard boosting?

  • Large dataset: XGBoost is parallelized and cache-optimized.

  • Built-in regularization

  • Missing data: XGBoost handles missing values automatically by learning the best default direction at each split.

  • Better optimization: Second-order information can give better-scaled updates; it does not guarantee faster convergence or better prediction in every problem.

  • Sparse Data: XGBoost has a sparsity-aware algorithm that efficiently handles sparse feature matrices like TF-IDF vectors.

Limitations

When do we NOT use XGBoost, not standard boosting?

  • Simplicity matters.

  • Small dataset.

  • Less optimization needed.

  • Higher interpretability needed.