A Hobbyist’s Notes on Gradient Boosting

Gene Boo, 2023 — reviewed and reorganized edition

Important note. This is an informal, layman-friendly learning document by a hobbyist coder, not a formal mathematical treatise. It is intended to build intuition and practical understanding. Do not rely on it as a sole source for formal proofs, academic theses, production model validation, or regulated model approval.

Table of Contents


Preface: Scope, Learning Path, and Terminology

This document explains four closely related ideas:

  1. Start with the big picture: boosting as repeated correction.
  2. Compare boosting with logistic regression, because this clarifies why boosting is powerful but less transparent.
  3. Learn the mathematical core: gradients, pseudo-residuals, trees, regularization, and logistic loss.
  4. Study the three major practical implementations: XGBoost, LightGBM, and CatBoost.
  5. Finish with the practical guide, timeline, mathematical summary, glossary, and appendix on high-performance computing.

Part I — The Big Picture

1. What Is Boosting?

1.1 Formal explanation

Boosting is an ensemble learning method. An ensemble combines many simple models into one stronger model. In gradient boosting, the final prediction function is an additive model:

FM(x)=F0(x)+m=1Mηfm(x), F_M(x) = F_0(x) + \sum_{m=1}^{M} \eta f_m(x),

where:

Most modern gradient boosting systems use decision trees as weak learners. Therefore, each fmf_m is usually a small regression tree.

The learning goal is to minimize an empirical loss:

L(F)=i=1nL(yi,F(xi)), \mathcal{L}(F) = \sum_{i=1}^{n} L\bigl(y_i, F(x_i)\bigr),

where:

1.2 Layman explanation

Imagine a student taking a practice exam. The first attempt is rough. The student then studies the mistakes, takes another attempt focused on those mistakes, and repeats. Each new attempt does not start from scratch; it corrects what the previous attempt got wrong.

Gradient boosting works in the same spirit:

  1. Start with a simple prediction.
  2. Measure the mistakes.
  3. Build a small model that focuses on correcting those mistakes.
  4. Add that correction to the previous model.
  5. Repeat many times.

The final model is like a team of small experts, where each expert specializes in correcting the remaining errors of the team so far.

2. The Additive Boosting Model

The essence of boosting is:

strong model=initial guess+many small corrections. \text{strong model} = \text{initial guess} + \text{many small corrections}.

A practical boosting update is:

Fm(x)=Fm1(x)+ηfm(x),0<η1. F_m(x) = F_{m-1}(x) + \eta f_m(x), \qquad 0 < \eta \le 1.

The learning rate η\eta controls how much of the new correction is accepted. A smaller η\eta makes learning more cautious. It usually requires more trees, but often improves generalization.

3. A First Regression Example

Suppose we want to predict house prices using one feature, floor area. The true prices are:

House True price
1 100
2 150
3 200

For squared-error regression, a common initial prediction is the mean target:

F0(x)=yˉ=100+150+2003=150. F_0(x) = \bar{y} = \frac{100 + 150 + 200}{3} = 150.

House True value yiy_i Initial prediction F0(xi)F_0(x_i) Residual yiF0(xi)y_i-F_0(x_i)
1 100 150 -50
2 150 150 0
3 200 150 50

A small tree is then trained to predict the residuals. Suppose the first tree predicts:

f1(x1)=40,f1(x2)=0,f1(x3)=40. f_1(x_1)=-40, \qquad f_1(x_2)=0, \qquad f_1(x_3)=40.

If the learning rate is η=0.5\eta=0.5, the updated prediction is:

F1(xi)=F0(xi)+ηf1(xi). F_1(x_i) = F_0(x_i) + \eta f_1(x_i).

Therefore:

F1(x1)=150+0.5(40)=130,F1(x2)=150+0.5(0)=150,F1(x3)=150+0.5(40)=170. \begin{aligned} F_1(x_1) &= 150 + 0.5(-40) = 130,\\ F_1(x_2) &= 150 + 0.5(0) = 150,\\ F_1(x_3) &= 150 + 0.5(40) = 170. \end{aligned}

The model has moved closer to the true prices. It has not fully corrected the errors because the learning rate deliberately takes a smaller step to reduce overfitting.


Part II — Boosting Compared with Logistic Regression

4. Logistic Regression: The Transparent Baseline

Logistic regression is a simple, interpretable linear classification model. For binary classification, it models the probability of class 11 as:

p(y=1x)=11+ez, p(y=1\mid x)=\frac{1}{1+e^{-z}},

where:

z=β0+β1x1+β2x2++βpxp. z=\beta_0+\beta_1x_1+\beta_2x_2+\cdots+\beta_px_p.

Equivalently, logistic regression assumes that the log-odds are linear in the features:

log(p1p)=β0+β1x1++βpxp. \log\left(\frac{p}{1-p}\right)=\beta_0+\beta_1x_1+\cdots+\beta_px_p.

Layman explanation

Logistic regression draws a relatively simple decision boundary. It says:

Each feature contributes a fixed amount to the final risk score.

For credit risk, one may think of it as:

risk score=base risk+effect of income+effect of age+effect of leverage+effect of delinquency count. \text{risk score} = \text{base risk} + \text{effect of income} + \text{effect of age} + \text{effect of leverage} + \text{effect of delinquency count}.

Each variable has a coefficient that is easy to explain.

Logistic regression objective

Logistic regression minimizes binary cross-entropy loss:

L(β)=i=1n[yilog(pi)+(1yi)log(1pi)], \mathcal{L}(\beta) = -\sum_{i=1}^{n}\left[y_i\log(p_i)+(1-y_i)\log(1-p_i)\right],

where:

pi=11+e(β0+βxi). p_i=\frac{1}{1+e^{-(\beta_0+\beta^\top x_i)}}.

The model directly learns coefficients β0,β1,,βp\beta_0,\beta_1,\ldots,\beta_p. Each coefficient tells us how a feature changes the log-odds of the event.

5. Boosting: The Nonlinear Challenger

Boosting builds a model by adding many small models sequentially:

FM(x)=F0(x)+m=1Mηfm(x). F_M(x)=F_0(x)+\sum_{m=1}^{M}\eta f_m(x).

For binary classification, the boosted raw score is often transformed into a probability through the sigmoid:

p(y=1x)=11+eFM(x). p(y=1\mid x)=\frac{1}{1+e^{-F_M(x)}}.

Each new tree tries to correct the mistakes of the previous trees.

Layman explanation

Boosting is more like a committee of small decision trees:

So boosting says:

Let many small models work together, each correcting the previous errors.

6. Logistic Regression vs Boosting: Practical Comparison

At a high level:

Logistic regression is a simple, transparent linear model. Boosting is a flexible ensemble method that combines many weak models, usually trees, to capture complex nonlinear patterns.

Dimension Logistic Regression Boosting / XGBoost / LightGBM / CatBoost
Basic form Single linear model Ensemble of many trees
Prediction Probability via sigmoid Score from many trees, often converted to probability
Main assumption Linear relationship in log-odds Few strict assumptions; learns nonlinear patterns
Feature interactions Must be manually added Automatically discovered by trees
Threshold effects Poor unless engineered Natural for tree splits
Feature engineering Often required Usually less required
Interpretability High Medium to low unless explained with SHAP, feature importance, PDP/ALE, or surrogate models
Overfitting risk Lower, especially when regularized Higher if not tuned carefully
Training speed Usually very fast Slower, especially with many trees, but optimized libraries are fast
Inference speed Very fast Fast, but usually slower than logistic regression
Small data Often strong and stable Can overfit if not controlled
Large data Works well Works well; LightGBM and XGBoost are especially scalable
Missing values Usually need imputation XGBoost, LightGBM, and CatBoost can often handle them more naturally
Categorical variables Need encoding CatBoost handles categoricals especially well
Probability calibration Often good when correctly specified May need calibration
Regulatory defensibility Strong Requires more explanation and governance
Best use Transparent baseline or regulated model High-performance predictive model

7. Worked Credit-Risk Example

Suppose you want to predict whether a borrower defaults. Features include:

7.1 Logistic regression approach

A logistic model may learn:

log(p1p)=β0+β1(income)+β2(debt ratio)+β3(missed payments). \log\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1(\text{income}) + \beta_2(\text{debt ratio}) + \beta_3(\text{missed payments}).

It assumes each feature has a relatively smooth directional effect. For example:

This is excellent for explanation, audit, and regulatory discussion because each coefficient has a clean interpretation.

7.2 Boosting approach

A boosting model can learn rules such as:

If missed payments > 2
and debt ratio > 45%
and income < 4000
then increase default risk sharply.

It can also learn different behavior in different regions:

For young borrowers, income may matter strongly.
For older borrowers, debt ratio may matter more.
For high-income borrowers, missed payments may dominate.

Boosting does not need one simple straight-line relationship. It can discover complicated combinations automatically.

7.3 Numerical comparison

Suppose we have two features:

and target:

y={1,default,0,no default. y= \begin{cases} 1, & \text{default},\\ 0, & \text{no default}. \end{cases}

Assume the logistic regression score is:

z=20.0001x1+0.05x2. z=-2-0.0001x_1+0.05x_2.

For a borrower with x1=3000x_1=3000 and x2=50x_2=50:

z=20.0001(3000)+0.05(50)=20.3+2.5=0.2. \begin{aligned} z &= -2 - 0.0001(3000) + 0.05(50)\\ &= -2 - 0.3 + 2.5\\ &= 0.2. \end{aligned}

So:

p=11+e0.20.5498. p=\frac{1}{1+e^{-0.2}}\approx 0.5498.

Logistic regression predicts a default probability of about 54.98%54.98\%.

A boosting model may instead use rule-based corrections:

Initial raw score: F_0 = 0
Tree 1: if debt ratio > 40, add 0.8
Tree 2: if income < 4000, add 0.5
Tree 3: if debt ratio > 60, add another 0.7

For this borrower, the first two rules apply but the third does not:

F(x)=0+0.8+0.5+0=1.3. F(x)=0+0.8+0.5+0=1.3.

Converted to probability:

p=11+e1.30.7858. p=\frac{1}{1+e^{-1.3}}\approx 0.7858.

Boosting predicts about 78.58%78.58\% default probability because it captured threshold-style rules.

8. Interpretability, Overfitting, Calibration, and Governance

8.1 Linearity versus nonlinearity

Logistic regression is linear in the log-odds:

log(p1p)=βx. \log\left(\frac{p}{1-p}\right)=\beta^\top x.

A one-unit change in a feature has a consistent additive effect on the log-odds unless transformations or interaction terms are manually added. For example, if age is included as x1x_1, the model assumes:

effect of age=β1x1. \text{effect of age}=\beta_1x_1.

If real-world risk is high for very young borrowers, lower for middle-aged borrowers, and higher again for elderly borrowers, logistic regression will not naturally capture that unless we add features such as age2\text{age}^2 or age buckets.

Boosting trees naturally capture nonlinearities and interactions:

If age < 25:
    use one risk rule
Else if age is between 25 and 60:
    use another risk rule
Else:
    use another risk rule

8.2 Coefficient interpretation in logistic regression

If the model is:

log(p1p)=β0+β1x1, \log\left(\frac{p}{1-p}\right)=\beta_0+\beta_1x_1,

then a one-unit increase in x1x_1 changes the log-odds by β1\beta_1. The odds multiplier is:

eβ1. e^{\beta_1}.

If β1=0.2\beta_1=0.2, then:

e0.21.221. e^{0.2}\approx 1.221.

This means a one-unit increase in x1x_1 multiplies the odds by about 1.2211.221, or increases the odds by about 22.1%22.1\%.

8.3 Why boosting is harder to explain

Boosting may contain hundreds or thousands of trees. Its prediction is not one simple equation. Interpretation usually requires tools such as:

Boosting can be explained, but not as directly as logistic regression.

8.4 Overfitting comparison

Regularized logistic regression can minimize:

i=1nL(yi,y^i)+λj=1pβj2, \sum_{i=1}^{n}L(y_i,\hat{y}_i)+\lambda\sum_{j=1}^{p}\beta_j^2,

where the penalty term:

λj=1pβj2 \lambda\sum_{j=1}^{p}\beta_j^2

discourages coefficients from becoming too large.

Boosting can overfit if:

Boosting is controlled using:

8.5 When each approach is better

Use logistic regression when:

Example use cases include traditional scorecards, medical risk models requiring simple explanations, regulatory credit models, quick baseline classifiers, and odds-ratio analysis.

Use boosting when:

Example use cases include fraud detection, credit default prediction challenger models, customer churn prediction, click-through-rate prediction, demand forecasting, ranking, pricing models, and operational-risk classification.

8.6 Baseline-and-challenger workflow

A common practical workflow is:

  1. Build a logistic regression baseline.
  2. Build a boosting model challenger.
  3. Compare AUC, log loss, accuracy, precision/recall, calibration, stability, interpretability, and out-of-time validation performance.
  4. Decide whether the performance gain from boosting justifies the added complexity.

This is especially useful in risk modelling because logistic regression is transparent, while boosting may deliver stronger predictive performance.

8.7 Calibration

Calibration concerns whether predicted probabilities correspond to observed event rates. For example, a calibrated predicted probability of 0.200.20 should roughly correspond to a true event rate of 20%20\%.

Logistic regression often gives reasonably calibrated probabilities if the model is correctly specified and validation is sound.

Boosting may rank observations very well but sometimes produce probabilities that need calibration before being interpreted literally. Common calibration methods include:


Part III — Gradient Boosting Mathematics

9. Gradient Boosting as Gradient Descent in Function Space

9.1 Formal explanation

In ordinary gradient descent, we update parameters such as θ\theta:

θm=θm1ηθL(θm1). \theta_m=\theta_{m-1}-\eta\nabla_{\theta}\mathcal{L}(\theta_{m-1}).

Gradient boosting follows a similar idea, but instead of directly updating a finite parameter vector, it updates an entire prediction function FF.

At iteration mm, compute the negative gradient of the loss with respect to the current prediction:

rim=[L(yi,F(xi))F(xi)]F=Fm1. r_{im}=-\left[\frac{\partial L(y_i,F(x_i))}{\partial F(x_i)}\right]_{F=F_{m-1}}.

The value rimr_{im} is called a pseudo-residual. A new tree fmf_m is trained to approximate these pseudo-residuals:

fmargminfi=1n(rimf(xi))2. f_m\approx\arg\min_f\sum_{i=1}^{n}\bigl(r_{im}-f(x_i)\bigr)^2.

Then update:

Fm(x)=Fm1(x)+ηfm(x). F_m(x)=F_{m-1}(x)+\eta f_m(x).

9.2 Layman explanation

The word gradient means direction of steepest increase. Therefore, the negative gradient points in the direction that reduces the loss most quickly.

For squared error, the negative gradient is simply the ordinary residual. For more complex losses, such as logistic loss, the negative gradient is a mathematically generalized version of the residual.

So instead of saying:

Fit the next tree to the errors.

Gradient boosting says more generally:

Fit the next tree to the direction that most reduces the chosen loss function.

9.3 Squared-error gradient example

For squared-error loss:

L(yi,F(xi))=12(yiF(xi))2. L(y_i,F(x_i))=\frac{1}{2}\bigl(y_i-F(x_i)\bigr)^2.

Differentiate with respect to F(xi)F(x_i):

LF(xi)=(yiF(xi)). \frac{\partial L}{\partial F(x_i)} = -\bigl(y_i-F(x_i)\bigr).

Therefore, the negative gradient is:

ri=LF(xi)=yiF(xi). r_i=-\frac{\partial L}{\partial F(x_i)}=y_i-F(x_i).

This confirms that, for squared-error regression, pseudo-residuals are the usual residuals. If yi=100y_i=100 and F(xi)=150F(x_i)=150, then:

ri=100150=50. r_i=100-150=-50.

The next tree should learn a negative correction for this observation.

10. Binary Classification with Logistic Loss

For binary classification, let yi{0,1}y_i\in\{0,1\}. The model often produces a raw score F(xi)F(x_i), also called a logit. This raw score is converted into a probability using the logistic sigmoid function:

pi=σ(F(xi))=11+eF(xi). p_i=\sigma(F(x_i))=\frac{1}{1+e^{-F(x_i)}}.

The binary logistic loss is:

L(yi,F(xi))=yilog(pi)(1yi)log(1pi). L(y_i,F(x_i))=-y_i\log(p_i)-(1-y_i)\log(1-p_i).

The first derivative with respect to the raw score is:

gi=LF(xi)=piyi. g_i=\frac{\partial L}{\partial F(x_i)}=p_i-y_i.

The negative gradient is:

ri=yipi. r_i=y_i-p_i.

The second derivative is:

hi=2LF(xi)2=pi(1pi). h_i=\frac{\partial^2L}{\partial F(x_i)^2}=p_i(1-p_i).

Classification correction example

Suppose:

yi=1,F0(xi)=0. y_i=1, \qquad F_0(x_i)=0.

Then:

pi=11+e0=0.5. p_i=\frac{1}{1+e^0}=0.5.

The gradient and negative gradient are:

gi=piyi=0.51=0.5,ri=gi=0.5. g_i=p_i-y_i=0.5-1=-0.5, \qquad r_i=-g_i=0.5.

The model should increase the raw score because the true class is 11 but the current probability is only 0.50.5.

If a tree predicts correction f1(xi)=0.8f_1(x_i)=0.8 and η=0.1\eta=0.1:

F1(xi)=0+0.1(0.8)=0.08. F_1(x_i)=0+0.1(0.8)=0.08.

The new probability is:

pi=11+e0.080.5200. p_i=\frac{1}{1+e^{-0.08}}\approx0.5200.

The probability moved from 0.50.5 to about 0.52000.5200, which is in the correct direction.

11. Decision Trees as Weak Learners

A decision tree partitions the feature space into terminal regions or leaves. If a tree has JJ leaves, it can be written as:

f(x)=j=1Jwj1{xRj}, f(x)=\sum_{j=1}^{J}w_j\mathbf{1}\{x\in R_j\},

where:

Layman explanation

A tree asks a sequence of yes/no questions:

At the end, the observation lands in a leaf. Each leaf gives a number. In boosting, that number is usually a correction to the current prediction.

Small tree example

Suppose a tree uses one split:

If area<1000 sq ft, go left; otherwise go right. \text{If area}<1000\text{ sq ft, go left; otherwise go right.}

Assume the leaf outputs are:

wL=30,wR=40. w_L=-30, \qquad w_R=40.

Then:

f(x)=301{area<1000}+401{area1000}. f(x)=-30\cdot\mathbf{1}\{\text{area}<1000\}+40\cdot\mathbf{1}\{\text{area}\ge1000\}.

If a house has area 900900, then f(x)=30f(x)=-30. If it has area 12001200, then f(x)=40f(x)=40.

12. Regularization in Gradient Boosting

Gradient boosting can overfit if trees are too deep, the learning rate is too high, or the number of trees is too large. Regularization methods include:

Learning-rate example

Suppose:

F0(xi)=100,f1(xi)=50. F_0(x_i)=100, \qquad f_1(x_i)=50.

If η=1\eta=1:

F1(xi)=100+1(50)=150. F_1(x_i)=100+1(50)=150.

If η=0.1\eta=0.1:

F1(xi)=100+0.1(50)=105. F_1(x_i)=100+0.1(50)=105.

A smaller learning rate moves more cautiously. It usually requires more trees but often improves generalization.


Part IV — XGBoost

13. What Is XGBoost?

XGBoost stands for Extreme Gradient Boosting. It is a scalable tree boosting system that extends classical gradient boosting with:

At boosting step tt, the model is:

y^i(t)=y^i(t1)+ft(xi). \hat{y}_i^{(t)}=\hat{y}_i^{(t-1)}+f_t(x_i).

The regularized objective is:

Obj(t)=i=1nL(yi,y^i(t1)+ft(xi))+Ω(ft). \mathcal{Obj}^{(t)}= \sum_{i=1}^{n}L\bigl(y_i,\hat{y}_i^{(t-1)}+f_t(x_i)\bigr)+\Omega(f_t).

A common tree penalty is:

Ω(ft)=γT+12λj=1Twj2. \Omega(f_t)=\gamma T+\frac{1}{2}\lambda\sum_{j=1}^{T}w_j^2.

Layman explanation

XGBoost is gradient boosting with stronger mathematics and stronger engineering. Classical gradient boosting says, “Use the direction of the error.” XGBoost says, “Use both the direction of the error and the curvature of the loss, and also punish trees that become unnecessarily complicated.”

Direction tells the model where to move. Curvature tells the model how cautious it should be.

Model update example

Suppose:

y^(0)=10,f1(x)=2. \hat{y}^{(0)}=10, \qquad f_1(x)=2.

Then:

y^(1)=10+2=12. \hat{y}^{(1)}=10+2=12.

If the next tree gives f2(x)=0.5f_2(x)=-0.5, then:

y^(2)=120.5=11.5. \hat{y}^{(2)}=12-0.5=11.5.

With a learning rate, many implementations update as:

y^(t)=y^(t1)+ηft(x). \hat{y}^{(t)}=\hat{y}^{(t-1)}+\eta f_t(x).

14. XGBoost’s Second-Order Taylor Approximation

XGBoost approximates the loss using a second-order Taylor expansion around the current prediction:

L(yi,y^i(t1)+ft(xi))L(yi,y^i(t1))+gift(xi)+12hift(xi)2, L\bigl(y_i,\hat{y}_i^{(t-1)}+f_t(x_i)\bigr) \approx L\bigl(y_i,\hat{y}_i^{(t-1)}\bigr) +g_if_t(x_i) +\frac{1}{2}h_if_t(x_i)^2,

where:

gi=[L(yi,y^)y^]y^=y^i(t1), g_i=\left[\frac{\partial L(y_i,\hat{y})}{\partial\hat{y}}\right]_{\hat{y}=\hat{y}_i^{(t-1)}},

and:

hi=[2L(yi,y^)y^2]y^=y^i(t1). h_i=\left[\frac{\partial^2L(y_i,\hat{y})}{\partial\hat{y}^2}\right]_{\hat{y}=\hat{y}_i^{(t-1)}}.

Ignoring constants independent of ftf_t, the approximate objective becomes:

Obj~(t)=i=1n[gift(xi)+12hift(xi)2]+Ω(ft). \tilde{\mathcal{Obj}}^{(t)} = \sum_{i=1}^{n}\left[g_if_t(x_i)+\frac{1}{2}h_if_t(x_i)^2\right]+\Omega(f_t).

Squared-error derivative example

Let:

L(y,y^)=12(yy^)2. L(y,\hat{y})=\frac{1}{2}(y-\hat{y})^2.

Then:

g=Ly^=y^y,h=2Ly^2=1. g=\frac{\partial L}{\partial\hat{y}}=\hat{y}-y, \qquad h=\frac{\partial^2L}{\partial\hat{y}^2}=1.

If y=10y=10 and y^=7\hat{y}=7:

g=710=3,h=1. g=7-10=-3, \qquad h=1.

The negative gradient is 33, meaning the prediction should increase.

15. XGBoost Optimal Leaf Weight

Suppose a tree has TT leaves. Let IjI_j be the set of training rows in leaf jj. Define:

Gj=iIjgi,Hj=iIjhi. G_j=\sum_{i\in I_j}g_i, \qquad H_j=\sum_{i\in I_j}h_i.

For a fixed tree structure, the objective contribution of leaf jj is:

Gjwj+12(Hj+λ)wj2+γ. G_jw_j+\frac{1}{2}(H_j+\lambda)w_j^2+\gamma.

Differentiate with respect to wjw_j:

wj[Gjwj+12(Hj+λ)wj2]=Gj+(Hj+λ)wj. \frac{\partial}{\partial w_j}\left[G_jw_j+\frac{1}{2}(H_j+\lambda)w_j^2\right] =G_j+(H_j+\lambda)w_j.

Set to zero:

Gj+(Hj+λ)wj=0. G_j+(H_j+\lambda)w_j=0.

Therefore:

wj=GjHj+λ. w_j^*=-\frac{G_j}{H_j+\lambda}.

The optimal objective value for the tree is:

Obj~=12j=1TGj2Hj+λ+γT. \tilde{\mathcal{Obj}}^*=-\frac{1}{2}\sum_{j=1}^{T}\frac{G_j^2}{H_j+\lambda}+\gamma T.

Leaf-value example

Suppose one leaf contains three observations:

g1=3,g2=2,g3=1, g_1=-3, \qquad g_2=-2, \qquad g_3=1,

and all Hessians are 11:

h1=h2=h3=1. h_1=h_2=h_3=1.

Then:

G=32+1=4,H=1+1+1=3. G=-3-2+1=-4, \qquad H=1+1+1=3.

With λ=1\lambda=1:

w=43+1=1. w^*=-\frac{-4}{3+1}=1.

This leaf adds 11 to the current prediction for observations that land in it.

16. XGBoost Split Gain

A candidate split divides a parent node into left and right child nodes. Let:

G=GL+GR,H=HL+HR. G=G_L+G_R, \qquad H=H_L+H_R.

The split gain is:

Gain=12[GL2HL+λ+GR2HR+λG2H+λ]γ. \text{Gain} =\frac{1}{2}\left[ \frac{G_L^2}{H_L+\lambda} +\frac{G_R^2}{H_R+\lambda} -\frac{G^2}{H+\lambda} \right]-\gamma.

XGBoost chooses splits with large positive gain.

Split-gain example

Suppose:

GL=4,HL=3,GR=2,HR=2. G_L=-4, \quad H_L=3, \quad G_R=2, \quad H_R=2.

Then:

G=4+2=2,H=3+2=5. G=-4+2=-2, \qquad H=3+2=5.

Let λ=1\lambda=1 and γ=0.1\gamma=0.1.

GL2HL+λ=(4)23+1=4, \frac{G_L^2}{H_L+\lambda}=\frac{(-4)^2}{3+1}=4,

GR2HR+λ=222+1=431.3333, \frac{G_R^2}{H_R+\lambda}=\frac{2^2}{2+1}=\frac{4}{3}\approx1.3333,

G2H+λ=(2)25+1=460.6667. \frac{G^2}{H+\lambda}=\frac{(-2)^2}{5+1}=\frac{4}{6}\approx0.6667.

Therefore:

Gain=12(4+1.33330.6667)0.1=2.2333. \text{Gain}=\frac{1}{2}(4+1.3333-0.6667)-0.1=2.2333.

Because the gain is positive, the split is useful.


Part V — LightGBM

17. What Is LightGBM?

LightGBM is a gradient boosting framework that uses tree-based learning algorithms and is designed for speed, memory efficiency, and scalability. Its major ideas include:

LightGBM asks:

How can we make gradient boosting much faster without losing much accuracy?

It does this by:

Why speed matters

Suppose a dataset has:

n=1,000,000 rows,d=1,000 features. n=1{,}000{,}000\text{ rows}, \qquad d=1{,}000\text{ features}.

Checking every possible split for every feature is expensive. If each feature has many distinct values, split finding can dominate training time.

LightGBM reduces split search by replacing raw continuous feature values with bins, such as:

age{0,1,2,,255}. \text{age}\in\{0,1,2,\ldots,255\}.

Instead of checking hundreds of thousands of unique values, it checks at most 256256 bin thresholds per feature.

18. Histogram-Based Split Finding

LightGBM discretizes continuous features into bins:

xi(k)bi(k){0,1,,B1}, x_i^{(k)}\mapsto b_i^{(k)}\in\{0,1,\ldots,B-1\},

where BB is the number of bins.

For each feature kk and bin bb, LightGBM accumulates gradient and Hessian sums:

Gk,b=i:bi(k)=bgi,Hk,b=i:bi(k)=bhi. G_{k,b}=\sum_{i:b_i^{(k)}=b}g_i, \qquad H_{k,b}=\sum_{i:b_i^{(k)}=b}h_i.

For a threshold at bin ss, the left child has:

GL=b=0sGk,b,HL=b=0sHk,b. G_L=\sum_{b=0}^{s}G_{k,b}, \qquad H_L=\sum_{b=0}^{s}H_{k,b}.

The right child has:

GR=GGL,HR=HHL. G_R=G-G_L, \qquad H_R=H-H_L.

The gain can use the same second-order form as other boosted tree systems:

Gain(k,s)=12[GL2HL+λ+GR2HR+λG2H+λ]γ. \text{Gain}(k,s) =\frac{1}{2}\left[ \frac{G_L^2}{H_L+\lambda} +\frac{G_R^2}{H_R+\lambda} -\frac{G^2}{H+\lambda} \right]-\gamma.

Histogram example

Row Feature value Bin Gradient gig_i Hessian hih_i
1 2.1 0 -2 1
2 2.7 0 -1 1
3 5.2 1 3 1
4 8.8 2 2 1

Bin statistics:

G0=2+(1)=3,H0=2, G_0=-2+(-1)=-3, \quad H_0=2,

G1=3,H1=1, G_1=3, \quad H_1=1,

G2=2,H2=1. G_2=2, \quad H_2=1.

A split at bin 00 puts bin 00 left and bins 1,21,2 right:

GL=3,HL=2,GR=3+2=5,HR=1+1=2. G_L=-3, \quad H_L=2, \quad G_R=3+2=5, \quad H_R=1+1=2.

These statistics are inserted into the gain formula.

19. Leaf-Wise Tree Growth

Many tree algorithms grow trees level-wise, meaning all nodes at the same depth are split before moving deeper. LightGBM grows trees leaf-wise, also called best-first growth.

At each step, LightGBM chooses the leaf whose split produces the largest loss reduction:

j=argmaxjΔLj, j^*=\arg\max_j\Delta\mathcal{L}_j,

where ΔLj\Delta\mathcal{L}_j is the gain from splitting leaf jj.

Layman explanation

Level-wise tree growth is like building every room on floor 1 before starting floor 2. Leaf-wise growth asks:

Which room expansion gives me the biggest benefit right now?

This can achieve lower loss with fewer splits. However, it can create deep, unbalanced trees, so LightGBM needs controls such as num_leaves, max_depth, and min_data_in_leaf.

Choosing the best leaf

Suppose three leaves have possible split gains:

ΔL1=0.3,ΔL2=1.8,ΔL3=0.6. \Delta\mathcal{L}_1=0.3, \qquad \Delta\mathcal{L}_2=1.8, \qquad \Delta\mathcal{L}_3=0.6.

LightGBM chooses:

j=argmax(0.3,1.8,0.6)=2. j^*=\arg\max(0.3,1.8,0.6)=2.

It splits leaf 22 first, not leaves 11 and 33 merely because they are at the same depth.

20. Gradient-Based One-Side Sampling (GOSS)

Gradient-Based One-Side Sampling keeps observations with large gradients and samples from observations with small gradients.

Let:

For small-gradient sampled observations, LightGBM applies the multiplier:

1ab. \frac{1-a}{b}.

The adjusted gradient estimate is:

G~=iAgi+1abiBgi. \tilde{G}=\sum_{i\in A}g_i+\frac{1-a}{b}\sum_{i\in B}g_i.

A similar adjusted sum can be used for split statistics.

GOSS example

Suppose there are 100100 observations and:

a=0.2,b=0.3. a=0.2, \qquad b=0.3.

This means:

The multiplier for sampled small-gradient observations is:

1ab=0.80.32.6667. \frac{1-a}{b}=\frac{0.8}{0.3}\approx2.6667.

If:

iAgi=5,iBgi=1.2, \sum_{i\in A}g_i=-5, \qquad \sum_{i\in B}g_i=1.2,

then:

G~=5+2.6667(1.2)=1.8. \tilde{G}=-5+2.6667(1.2)=-1.8.

21. Exclusive Feature Bundling (EFB)

Exclusive Feature Bundling combines sparse features that are rarely nonzero at the same time. If two features are mutually exclusive, they can be placed into one bundled feature without much information loss.

Two features aa and bb are exclusive if approximately:

xi(a)0xi(b)=0, x_i^{(a)}\ne0\Rightarrow x_i^{(b)}=0,

and:

xi(b)0xi(a)=0. x_i^{(b)}\ne0\Rightarrow x_i^{(a)}=0.

Bundling reduces the effective number of features:

ddbundle,dbundle<d. d\rightarrow d_{\text{bundle}}, \qquad d_{\text{bundle}}<d.

EFB example

Row Feature A Feature B
1 1 0
2 0 1
3 0 0
4 1 0

Feature A and Feature B are never nonzero at the same time. They can be bundled. One possible representation is:

zi=xi(A)+cxi(B), z_i=x_i^{(A)}+c\cdot x_i^{(B)},

where cc is an offset chosen so values from Feature A and Feature B do not collide.

If c=10c=10:

Row Bundled feature ziz_i
1 1
2 10
3 0
4 1

The model can still recover the split meaning because the value ranges are separated.


Part VI — CatBoost

22. What Is CatBoost?

CatBoost stands for Categorical Boosting. It is a gradient boosting algorithm designed to handle categorical variables robustly and reduce target leakage.

Its major ideas include:

Many real datasets contain categorical variables such as country, merchant, product type, customer segment, industry code, and branch name. Ordinary machine learning models need these categories converted into numbers. Bad conversion can leak the answer into the input features. CatBoost was designed to avoid that kind of leakage.

Why naïve target encoding leaks

Suppose we have a categorical feature City and binary target Default:

Row City Default
1 A 1
2 A 0
3 B 1
4 B 1

A naïve target encoding for City A is:

TE(A)=1+02=0.5. \text{TE}(A)=\frac{1+0}{2}=0.5.

For City B:

TE(B)=1+12=1. \text{TE}(B)=\frac{1+1}{2}=1.

The problem is that row 33 gets an encoded value of 11 partly because its own target is 11. For rare categories, this leakage can become severe.

23. Ordered Target Statistics

CatBoost uses permutations to compute target statistics using only earlier rows in the permutation.

Let σ\sigma be a random permutation of the training rows. For row ii, the ordered target statistic for category value cc can be written as:

OTSi(c)=j:σ(j)<σ(i),xj=cyj+apj:σ(j)<σ(i),xj=c1+a, \text{OTS}_i(c) = \frac{\sum_{j:\sigma(j)<\sigma(i),\,x_j=c}y_j+ap} {\sum_{j:\sigma(j)<\sigma(i),\,x_j=c}1+a},

where:

Layman explanation

CatBoost pretends the data arrives in an order. When encoding a row, it only looks at previous rows, not the row’s own answer. This is like calculating a batting average before the current game, not after including the current game’s result.

Ordered-encoding example

Suppose the permutation order is:

1234. 1\rightarrow2\rightarrow3\rightarrow4.

The data is:

Row City Default
1 A 1
2 A 0
3 B 1
4 A 1

The global prior is:

p=1+0+1+14=0.75. p=\frac{1+0+1+1}{4}=0.75.

Let smoothing be a=1a=1.

For row 11, City A has no previous City A rows:

OTS1(A)=0+1(0.75)0+1=0.75. \text{OTS}_1(A)=\frac{0+1(0.75)}{0+1}=0.75.

For row 22, City A has one previous City A row with target 11:

OTS2(A)=1+1(0.75)1+1=0.875. \text{OTS}_2(A)=\frac{1+1(0.75)}{1+1}=0.875.

For row 44, City A has previous City A rows 11 and 22, with targets 11 and 00:

OTS4(A)=1+0+1(0.75)2+1=1.7530.5833. \text{OTS}_4(A)=\frac{1+0+1(0.75)}{2+1}=\frac{1.75}{3}\approx0.5833.

Notice row 44's own target is not included in its encoding.

24. Ordered Boosting

Standard boosting can suffer from prediction shift because the model’s prediction for a training row may be influenced by target information from that same row through earlier fitted models.

CatBoost’s ordered boosting uses permutations so that the residual or gradient for an observation is computed using a model trained only on observations earlier in the permutation.

Conceptually, for row ii under permutation σ\sigma, CatBoost aims to compute:

gi=[L(yi,F(xi))F(xi)]F=F<i, g_i= \left[ \frac{\partial L(y_i,F(x_i))}{\partial F(x_i)} \right]_{F=F_{<i}},

where F<iF_{<i} denotes a model constructed without using row ii or later rows in that permutation.

Layman explanation

CatBoost tries to make training behave more like real prediction. In real deployment, the model predicts new unseen rows; it does not get to use the target of the row it is predicting.

Ordered boosting imitates this: when estimating how wrong the model is on a row, it avoids letting that row’s own target sneak into the model that produced the prediction.

Ordered-logic example

Suppose the permutation is:

A,B,C,D. A, B, C, D.

To compute the correction for row CC, ordered boosting uses a model trained only from earlier rows:

{A,B}. \{A,B\}.

It does not use {C,D}\{C,D\}. Therefore, row CC is treated more like a future unseen observation, reducing leakage and prediction shift.

25. Symmetric or Oblivious Trees

CatBoost commonly uses symmetric decision trees, also called oblivious trees. At each depth, the same split condition is applied across all nodes at that depth.

A depth-DD oblivious tree has at most:

2D 2^D

leaves.

The leaf index can be computed from the binary outcomes of the DD split tests:

(x)=d=0D12d1{sd(x)=1}, \ell(x)=\sum_{d=0}^{D-1}2^d\mathbf{1}\{s_d(x)=1\},

where sd(x)s_d(x) is the split decision at depth dd.

Depth-2 example

Suppose a depth-2 oblivious tree uses:

s0(x)=1{Age>40}, s_0(x)=\mathbf{1}\{\text{Age}>40\},

and:

s1(x)=1{Income>100000}. s_1(x)=\mathbf{1}\{\text{Income}>100000\}.

The leaf index is:

(x)=20s0(x)+21s1(x). \ell(x)=2^0s_0(x)+2^1s_1(x).

If Age >40>40 and Income >100000>100000, then:

s0(x)=1,s1(x)=1, s_0(x)=1, \qquad s_1(x)=1,

so:

(x)=1+2=3. \ell(x)=1+2=3.

The observation lands in leaf 33.


Part VII — Choosing and Using the Algorithms

26. Conceptual Comparison

Topic Gradient Boosting XGBoost LightGBM CatBoost
Core idea Add weak learners to follow negative gradients Gradient boosting with second-order regularized objective Fast and memory-efficient GBDT Boosting designed for categorical variables and reduced leakage
Main optimization First-order functional gradient descent Gradients plus Hessians Histograms, GOSS, EFB, leaf-wise growth Ordered target statistics and ordered boosting
Tree growth Usually shallow trees Depth-wise or configurable Leaf-wise best-first Symmetric/oblivious trees
Categorical features Need preprocessing Supports categorical features in newer versions but still often encoded Supports categorical features, often with care Native categorical handling is a core strength
Strength Conceptual simplicity Accuracy, regularization, scalability Speed and memory efficiency Minimal categorical preprocessing and strong defaults
Main risk Overfitting if too many trees Hyperparameter complexity Overfitting with leaf-wise deep growth Can be slower depending on settings and data

27. Which Algorithm Should You Use?

Use basic gradient boosting when:

Use XGBoost when:

Use LightGBM when:

Use CatBoost when:

A simple rule of thumb:

Choice example

Suppose you are building a default prediction model with these features:

If there are many categorical variables such as branch code and industry code, CatBoost is a natural first candidate. If the dataset has 1010 million rows and 1,0001{,}000 mostly numerical or sparse features, LightGBM is a natural first candidate. If you need carefully regularized performance and detailed control, XGBoost is a strong candidate.

28. Hyperparameters Explained Simply

28.1 Common hyperparameters

Number of trees.

M=number of boosting rounds. M=\text{number of boosting rounds}.

This is the number of correction steps. Too few trees underfit; too many can overfit unless controlled by learning rate and early stopping.

Learning rate.

Fm(x)=Fm1(x)+ηfm(x). F_m(x)=F_{m-1}(x)+\eta f_m(x).

A small η\eta means careful learning. A large η\eta means aggressive learning.

Maximum depth. A tree with depth DD can have up to:

2D 2^D

leaves in a full binary tree. Deeper trees can learn more complex interactions but can also memorize noise.

Subsample. If qq is the row subsampling rate, each boosting round trains on approximately:

qn qn

observations.

Column sample. If cc is the column subsampling rate, each tree or split considers approximately:

cd cd

features.

28.2 XGBoost-specific hyperparameters

A larger λ\lambda shrinks leaf values:

wj=GjHj+λ. w_j^*=-\frac{G_j}{H_j+\lambda}.

If λ\lambda increases, the denominator increases and wjw_j^* decreases in magnitude.

28.3 LightGBM-specific hyperparameters

For a full binary tree:

num_leaves2max_depth. \text{num\_leaves}\le2^{\text{max\_depth}}.

For LightGBM, controlling num_leaves is crucial because leaf-wise growth can produce deep branches.

28.4 CatBoost-specific hyperparameters

A depth-DD symmetric CatBoost tree has up to:

2D 2^D

leaves.

29. Full Worked Mini-Example Across Algorithms

29.1 Dataset

Row Area Age True value yy
1 800 20 100
2 1000 15 120
3 1200 10 150
4 1500 5 200

Initial prediction:

F0=yˉ=100+120+150+2004=142.5. F_0=\bar{y}=\frac{100+120+150+200}{4}=142.5.

Residuals for squared-error gradient boosting are:

ri=yiF0(xi). r_i=y_i-F_0(x_i).

Thus:

r1=42.5,r2=22.5,r3=7.5,r4=57.5. r_1=-42.5, \quad r_2=-22.5, \quad r_3=7.5, \quad r_4=57.5.

29.2 Gradient boosting step

A simple tree might split on:

Area<1100. \text{Area}<1100.

Left rows: 1,21,2. Right rows: 3,43,4.

Left leaf residual mean:

wL=42.5+(22.5)2=32.5. w_L=\frac{-42.5+(-22.5)}{2}=-32.5.

Right leaf residual mean:

wR=7.5+57.52=32.5. w_R=\frac{7.5+57.5}{2}=32.5.

If η=0.1\eta=0.1, predictions update as:

F1=142.5+0.1(32.5)=139.25for rows 1,2, F_1=142.5+0.1(-32.5)=139.25 \quad \text{for rows }1,2,

and:

F1=142.5+0.1(32.5)=145.75for rows 3,4. F_1=142.5+0.1(32.5)=145.75 \quad \text{for rows }3,4.

29.3 XGBoost step

For squared error:

gi=y^iyi,hi=1. g_i=\hat{y}_i-y_i, \qquad h_i=1.

At F0=142.5F_0=142.5:

g1=42.5,g2=22.5,g3=7.5,g4=57.5. g_1=42.5, \quad g_2=22.5, \quad g_3=-7.5, \quad g_4=-57.5.

For the same split, left node:

GL=42.5+22.5=65,HL=2. G_L=42.5+22.5=65, \qquad H_L=2.

Right node:

GR=7.557.5=65,HR=2. G_R=-7.5-57.5=-65, \qquad H_R=2.

Let λ=1\lambda=1. Leaf weights are:

wL=652+1=21.6667, w_L^*=-\frac{65}{2+1}=-21.6667,

wR=652+1=21.6667. w_R^*=-\frac{-65}{2+1}=21.6667.

XGBoost’s regularization reduces the correction magnitude compared with ordinary residual means.

29.4 LightGBM step

LightGBM may first bin Area values:

Area Bin
800 0
1000 0
1200 1
1500 2

It evaluates splits over bins rather than exact Area values. A split after bin 00 produces the same grouping as Area < 1100:

The gain is computed using gradient and Hessian sums, while the histogram makes this faster.

29.5 CatBoost step

If there is also a categorical variable such as Region:

Row Region True value yy
1 North 100
2 North 120
3 South 150
4 North 200

A naïve encoding for North would be:

100+120+2003=140. \frac{100+120+200}{3}=140.

But for row 11, this uses row 11's own target, which leaks information. CatBoost instead uses ordered statistics. If the permutation is 1,2,3,41,2,3,4, then row 22's North statistic can use row 11, but row 11 cannot use itself.

30. Common Mistakes and Safeguards

30.1 Data leakage

Data leakage occurs when training features contain information that would not be available at prediction time.

Example:

Feature=average default rate of this exact customer including current outcome. \text{Feature}=\text{average default rate of this exact customer including current outcome}.

This is invalid because it uses the answer to help predict the answer.

Safeguards include computing encodings and aggregations using cross-validation, time-aware splits, or ordered methods such as CatBoost’s ordered statistics.

30.2 Improper validation

If data has time ordering, random train-test splits can be misleading. For time-dependent data, use:

train period<validation period<test period. \text{train period}<\text{validation period}<\text{test period}.

30.3 Too many trees without early stopping

Training loss usually decreases as trees are added, but validation loss may eventually increase. Let validation loss after mm trees be Lval(m)\mathcal{L}_{\text{val}}^{(m)}. Early stopping selects:

m=argminmLval(m). m^*=\arg\min_m\mathcal{L}_{\text{val}}^{(m)}.

30.4 Misinterpreting feature importance

Feature importance can be measured in different ways:

These do not always agree. A highly correlated feature may look less important if another correlated feature is selected first.

31. Final Practical Checklist

Before fitting a gradient boosting model, answer these questions:


Part VIII — Historical Maturity Timeline

32. XGBoost, LightGBM, and CatBoost Maturity Timeline

Short answer: XGBoost matured first, around 2016–2020; LightGBM matured around 2017–2021; CatBoost matured around 2018–2021/2022.

However, “mature” depends on whether we mean:

Library Initial / Public Emergence Research Maturity Production / Stable Maturity Practical Interpretation
XGBoost Early-to-mid 2010s; major paper in 2016 2016, after Chen & Guestrin’s KDD paper formalized it as a scalable tree boosting system 2020, with v1.0.0 marking semantic versioning, governance, and production ecosystem improvements Mature earliest; by 2016 it was widely trusted in Kaggle and industry, and by 2020 it had stronger formal project maturity
LightGBM 2016 original release period; paper in 2017 2017, after the NeurIPS paper introduced GOSS and EFB 2020–2021, around v3.0.0/v3.3.0 when API, TreeSHAP, ranking, constraints, packaging, and sklearn support improved Matured after XGBoost, mainly because it needed time to prove speed and large-scale advantages
CatBoost Open-sourced in July 2017 2018, after the NeurIPS paper on ordered boosting and categorical features 2021, with v1.0.0 described by the project as stable and production-ready Matured last among the three, but became especially strong for categorical-heavy datasets

32.1 XGBoost: mature by 2016, institutionally mature by 2020

XGBoost’s major maturity point was 2016, when the paper “XGBoost: A Scalable Tree Boosting System” was published and positioned XGBoost as a scalable, efficient, production-grade tree boosting system capable of handling very large datasets.

If maturity is defined as stable software governance and semantic versioning, then February 19, 2020 is a stronger date. XGBoost v1.0.0 was released as a major milestone, adopting Apache-style governance, semantic versioning, improved installation, better multi-core CPU scaling, Kubernetes support, and Dask integration.

Practical judgment:

32.2 LightGBM: mature by 2017, operationally mature by 2020–2021

LightGBM emerged from Microsoft Research and was publicly associated with the 2017 NeurIPS paper, which introduced:

The paper reported that LightGBM could speed up conventional Gradient Boosting Decision Tree training by up to over 20 times while maintaining almost the same accuracy.

From a software maturity perspective, LightGBM’s mature stage is best placed around 2020–2021. Version v3.0.0 was released on August 30, 2020, and included production-relevant features such as improved Python/R support, interaction constraints, sparse TreeSHAP support, ranking enhancements, monotone-constraint improvements, and better scikit-learn compatibility. LightGBM continued maturing through v3.3.0 in October 2021, after which it became a common default choice for large tabular datasets because of its speed, low memory usage, distributed capability, and GPU support.

Practical judgment:

32.3 CatBoost: mature by 2018, production-ready by 2021

CatBoost was open-sourced in July 2017 by Yandex and was designed specifically to handle:

Its research maturity point was 2018, when the NeurIPS paper “CatBoost: Unbiased Boosting with Categorical Features” formally introduced and analyzed ordered boosting and categorical-feature handling to reduce prediction shift and target leakage.

Its clearest software maturity point was v1.0.0, where the project stated that CatBoost was considered stable and production-ready and already used in many companies and individual projects.

Practical judgment:

32.4 Final ranking by maturity timing

  1. XGBoost — matured first, around 2016, with software/governance maturity by 2020.
  2. LightGBM — matured next, around 2017, with operational maturity around 2020–2021.
  3. CatBoost — matured after that, around 2018, with explicit production-ready maturity around 2021.

Part IX — Mathematical Summary and Glossary

33. Mathematical Summary

33.1 Generic gradient boosting

FM(x)=F0(x)+m=1Mηfm(x). F_M(x)=F_0(x)+\sum_{m=1}^{M}\eta f_m(x).

rim=[L(yi,F(xi))F(xi)]F=Fm1. r_{im}=-\left[\frac{\partial L(y_i,F(x_i))}{\partial F(x_i)}\right]_{F=F_{m-1}}.

fmargminfi=1n(rimf(xi))2. f_m\approx\arg\min_f\sum_{i=1}^{n}(r_{im}-f(x_i))^2.

33.2 Logistic classification

pi=11+eF(xi). p_i=\frac{1}{1+e^{-F(x_i)}}.

L(yi,F(xi))=yilog(pi)(1yi)log(1pi). L(y_i,F(x_i))=-y_i\log(p_i)-(1-y_i)\log(1-p_i).

gi=piyi,hi=pi(1pi). g_i=p_i-y_i, \qquad h_i=p_i(1-p_i).

33.3 XGBoost objective

Obj(t)=i=1nL(yi,y^i(t1)+ft(xi))+Ω(ft). \mathcal{Obj}^{(t)}= \sum_{i=1}^{n}L\left(y_i,\hat{y}_i^{(t-1)}+f_t(x_i)\right)+\Omega(f_t).

Ω(ft)=γT+12λj=1Twj2. \Omega(f_t)=\gamma T+\frac{1}{2}\lambda\sum_{j=1}^{T}w_j^2.

wj=GjHj+λ. w_j^*=-\frac{G_j}{H_j+\lambda}.

Gain=12[GL2HL+λ+GR2HR+λG2H+λ]γ. \text{Gain}=\frac{1}{2}\left[ \frac{G_L^2}{H_L+\lambda} +\frac{G_R^2}{H_R+\lambda} -\frac{G^2}{H+\lambda} \right]-\gamma.

33.4 LightGBM histogram

xi(k)bi(k){0,1,,B1}. x_i^{(k)}\mapsto b_i^{(k)}\in\{0,1,\ldots,B-1\}.

Gk,b=i:bi(k)=bgi,Hk,b=i:bi(k)=bhi. G_{k,b}=\sum_{i:b_i^{(k)}=b}g_i, \qquad H_{k,b}=\sum_{i:b_i^{(k)}=b}h_i.

33.5 CatBoost ordered target statistic

OTSi(c)=j:σ(j)<σ(i),xj=cyj+apj:σ(j)<σ(i),xj=c1+a. \text{OTS}_i(c)= \frac{\sum_{j:\sigma(j)<\sigma(i),\,x_j=c}y_j+ap} {\sum_{j:\sigma(j)<\sigma(i),\,x_j=c}1+a}.

34. Glossary and Interpretation of Mathematical Formulae

This section collects the main formulae, symbols, and interpretations used throughout the document.

34.1 Additive boosting model

Formula:

FM(x)=F0(x)+m=1Mηfm(x). F_M(x)=F_0(x)+\sum_{m=1}^{M}\eta f_m(x).

Symbols:

Example: if F0(x)=100F_0(x)=100, f1(x)=20f_1(x)=20, f2(x)=5f_2(x)=-5, and η=0.1\eta=0.1, then:

F2(x)=100+0.1(20)+0.1(5)=101.5. F_2(x)=100+0.1(20)+0.1(-5)=101.5.

34.2 Empirical loss function

Formula:

L(F)=i=1nL(yi,F(xi)). \mathcal{L}(F)=\sum_{i=1}^{n}L(y_i,F(x_i)).

Symbols:

If three observation-level losses are 4,9,14,9,1, then total loss is 1414.

34.3 Gradient descent parameter update

Formula:

θm=θm1ηθL(θm1). \theta_m=\theta_{m-1}-\eta\nabla_{\theta}\mathcal{L}(\theta_{m-1}).

The gradient points uphill in loss. Subtracting it moves downhill. If θm1=10\theta_{m-1}=10, θL=3\nabla_{\theta}\mathcal{L}=3, and η=0.1\eta=0.1, then:

θm=100.1(3)=9.7. \theta_m=10-0.1(3)=9.7.

34.4 Pseudo-residual or negative gradient

Formula:

rim=[L(yi,F(xi))F(xi)]F=Fm1. r_{im}= -\left[\frac{\partial L(y_i,F(x_i))}{\partial F(x_i)}\right]_{F=F_{m-1}}.

The pseudo-residual tells the next tree what needs to be fixed. For squared error, it becomes the ordinary residual:

ri=yiF(xi). r_i=y_i-F(x_i).

If y=100y=100 and F=80F=80, then r=20r=20, so the model should increase its prediction.

34.5 Squared-error loss and residual

Loss:

L(yi,F(xi))=12(yiF(xi))2. L(y_i,F(x_i))=\frac{1}{2}(y_i-F(x_i))^2.

Residual:

ri=yiF(xi). r_i=y_i-F(x_i).

The factor 12\frac{1}{2} does not change the optimization target; it simplifies derivatives. If yi=100y_i=100 and F(xi)=90F(x_i)=90, then:

L=12(10)2=50. L=\frac{1}{2}(10)^2=50.

34.6 Logistic sigmoid, loss, gradient, and Hessian

Sigmoid:

pi=σ(F(xi))=11+eF(xi). p_i=\sigma(F(x_i))=\frac{1}{1+e^{-F(x_i)}}.

Binary logistic loss:

L(yi,F(xi))=yilog(pi)(1yi)log(1pi). L(y_i,F(x_i))=-y_i\log(p_i)-(1-y_i)\log(1-p_i).

Gradient:

gi=LF(xi)=piyi. g_i=\frac{\partial L}{\partial F(x_i)}=p_i-y_i.

Hessian:

hi=pi(1pi). h_i=p_i(1-p_i).

The sigmoid maps any real-valued score to a probability between 00 and 11. The gradient tells whether the raw score is too high or too low. The Hessian measures curvature and is largest near pi=0.5p_i=0.5.

Examples:

34.7 Decision tree as leaf regions

Formula:

f(x)=j=1Jwj1{xRj}. f(x)=\sum_{j=1}^{J}w_j\mathbf{1}\{x\in R_j\}.

A decision tree partitions feature space into JJ disjoint leaf regions. Each observation belongs to one leaf region, and the tree returns that leaf’s weight.

34.8 XGBoost objective, penalty, Taylor approximation, leaf weight, and gain

Objective:

Obj(t)=i=1nL(yi,y^i(t1)+ft(xi))+Ω(ft). \mathcal{Obj}^{(t)}= \sum_{i=1}^{n}L\bigl(y_i,\hat{y}_i^{(t-1)}+f_t(x_i)\bigr)+\Omega(f_t).

Penalty:

Ω(ft)=γT+12λj=1Twj2. \Omega(f_t)=\gamma T+\frac{1}{2}\lambda\sum_{j=1}^{T}w_j^2.

Taylor approximation:

L(yi,y^i(t1)+ft(xi))L(yi,y^i(t1))+gift(xi)+12hift(xi)2. L\bigl(y_i,\hat{y}_i^{(t-1)}+f_t(x_i)\bigr) \approx L\bigl(y_i,\hat{y}_i^{(t-1)}\bigr) +g_if_t(x_i)+\frac{1}{2}h_if_t(x_i)^2.

Gradient and Hessian definitions:

gi=[L(yi,y^)y^]y^=y^i(t1),hi=[2L(yi,y^)y^2]y^=y^i(t1). g_i=\left[\frac{\partial L(y_i,\hat{y})}{\partial\hat{y}}\right]_{\hat{y}=\hat{y}_i^{(t-1)}}, \qquad h_i=\left[\frac{\partial^2L(y_i,\hat{y})}{\partial\hat{y}^2}\right]_{\hat{y}=\hat{y}_i^{(t-1)}}.

Optimal leaf weight:

wj=GjHj+λ. w_j^*=-\frac{G_j}{H_j+\lambda}.

Split gain:

Gain=12[GL2HL+λ+GR2HR+λG2H+λ]γ. \text{Gain}=\frac{1}{2}\left[ \frac{G_L^2}{H_L+\lambda} +\frac{G_R^2}{H_R+\lambda} -\frac{G^2}{H+\lambda} \right]-\gamma.

Here GjG_j and HjH_j are sums of gradients and Hessians in leaf jj. γ\gamma penalizes additional leaves or splits, and λ\lambda shrinks leaf weights.

34.9 LightGBM histogram, leaf-wise growth, GOSS, and EFB

Histogram binning:

xi(k)bi(k){0,1,,B1}. x_i^{(k)}\mapsto b_i^{(k)}\in\{0,1,\ldots,B-1\}.

Gradient and Hessian bin sums:

Gk,b=i:bi(k)=bgi,Hk,b=i:bi(k)=bhi. G_{k,b}=\sum_{i:b_i^{(k)}=b}g_i, \qquad H_{k,b}=\sum_{i:b_i^{(k)}=b}h_i.

Leaf-wise rule:

j=argmaxjΔLj. j^*=\arg\max_j\Delta\mathcal{L}_j.

GOSS adjusted gradient estimate:

G~=iAgi+1abiBgi. \tilde{G}=\sum_{i\in A}g_i+\frac{1-a}{b}\sum_{i\in B}g_i.

Exclusive feature condition:

xi(a)0xi(b)=0,xi(b)0xi(a)=0. x_i^{(a)}\ne0\Rightarrow x_i^{(b)}=0, \qquad x_i^{(b)}\ne0\Rightarrow x_i^{(a)}=0.

Bundled feature representation:

zi=xi(A)+cxi(B). z_i=x_i^{(A)}+c\cdot x_i^{(B)}.

34.10 CatBoost ordered statistics, ordered boosting, and symmetric trees

Ordered target statistic:

OTSi(c)=j:σ(j)<σ(i),xj=cyj+apj:σ(j)<σ(i),xj=c1+a. \text{OTS}_i(c)= \frac{\sum_{j:\sigma(j)<\sigma(i),\,x_j=c}y_j+ap} {\sum_{j:\sigma(j)<\sigma(i),\,x_j=c}1+a}.

Ordered boosting gradient:

gi=[L(yi,F(xi))F(xi)]F=F<i. g_i= \left[ \frac{\partial L(y_i,F(x_i))}{\partial F(x_i)} \right]_{F=F_{<i}}.

Symmetric tree leaf count:

2D. 2^D.

Leaf index:

(x)=d=0D12d1{sd(x)=1}. \ell(x)=\sum_{d=0}^{D-1}2^d\mathbf{1}\{s_d(x)=1\}.

34.11 Early stopping, row sampling, and column sampling

Early stopping:

m=argminmLval(m). m^*=\arg\min_m\mathcal{L}_{\text{val}}^{(m)}.

Row subsampling count:

qn. qn.

Column subsampling count:

cd. cd.

Full binary tree leaf limit:

num_leaves2max_depth. \text{num\_leaves}\le2^{\text{max\_depth}}.

Initial prediction for squared-error regression:

F0(x)=yˉ,yˉ=1ni=1nyi. F_0(x)=\bar{y},\qquad \bar{y}=\frac{1}{n}\sum_{i=1}^{n}y_i.

34.12 Master glossary of common symbols

Dataset and prediction symbols

Indexing symbols

Loss and optimization symbols

Gradient and Hessian symbols

Tree symbols

LightGBM symbols

CatBoost symbols

34.13 Final interpretation

All the formulae in gradient boosting, XGBoost, LightGBM, and CatBoost revolve around one core idea:

Learn from the remaining error, add a controlled correction, and repeat. \text{Learn from the remaining error, add a controlled correction, and repeat.}

Gradient Boosting focuses on the negative gradient. XGBoost improves this with second-order information and explicit regularization. LightGBM improves computational efficiency using histograms, sampling, and feature bundling. CatBoost improves categorical-feature handling and reduces leakage using ordered methods.

In plain English:

Boosting is a disciplined process of repeatedly asking: what mistakes remain, how should I correct them, and how do I avoid correcting them too aggressively?


Appendix A — Vectorization, BLAS, Distributed Computing, and GPUs

This appendix builds on the scalar-gradient and scalar-Hessian explanation. The key idea is:

In ordinary regression and binary classification boosting, each row has a scalar gradient and scalar Hessian value. Across a large dataset, these scalar values become large vectors that can be processed efficiently using vectorized CPU operations, BLAS-style numerical routines, GPU parallelism, and distributed computing.

A.1 Scalar gradient and scalar Hessian per row

The Hessian looks like a single number because the model is usually predicting one number per row:

Thus:

scalar predictionscalar gradient and scalar Hessian value. \text{scalar prediction}\Rightarrow\text{scalar gradient and scalar Hessian value}.

For one row ii:

gi=LiF(xi),hi=2LiF(xi)2. g_i=\frac{\partial L_i}{\partial F(x_i)}, \qquad h_i=\frac{\partial^2L_i}{\partial F(x_i)^2}.

If the model predicts several numbers at once, such as one score per class in multiclass classification, then the gradient becomes a vector and the Hessian becomes a matrix.

A.2 From one row to the whole dataset

For a dataset with nn rows, each row has its own gradient:

g1,g2,,gn, g_1,g_2,\ldots,g_n,

and Hessian:

h1,h2,,hn. h_1,h_2,\ldots,h_n.

These can be collected into vectors:

g=[g1g2gn],h=[h1h2hn]. g=\begin{bmatrix}g_1\\g_2\\\vdots\\g_n\end{bmatrix}, \qquad h=\begin{bmatrix}h_1\\h_2\\\vdots\\h_n\end{bmatrix}.

For binary classification:

g=py, g=p-y,

where:

p=[p1p2pn],y=[y1y2yn], p=\begin{bmatrix}p_1\\p_2\\\vdots\\p_n\end{bmatrix}, \qquad y=\begin{bmatrix}y_1\\y_2\\\vdots\\y_n\end{bmatrix},

and:

h=p(1p), h=p\odot(1-p),

where \odot means element-wise multiplication.

Vectorized thinking says:

Calculate the errors for all rows at the same time.

Modern CPUs and GPUs are designed to perform many similar numerical operations in parallel.

A.3 Why this matters for boosting

For a leaf jj, boosted-tree algorithms compute:

Gj=iIjgi,Hj=iIjhi, G_j=\sum_{i\in I_j}g_i, \qquad H_j=\sum_{i\in I_j}h_i,

where IjI_j is the set of rows falling into leaf jj.

The optimal leaf weight is:

wj=GjHj+λ. w_j^*=-\frac{G_j}{H_j+\lambda}.

Training repeatedly performs operations such as:

These operations repeat across many rows, features, candidate split points, and trees. Efficient vectorized computation is therefore crucial.

A.4 BLAS-style matrix and vector operations

BLAS stands for Basic Linear Algebra Subprograms. BLAS-style operations are highly optimized routines for vector and matrix computation, including:

Boosted trees are not purely matrix-multiplication models like neural networks, but they still benefit from BLAS-style thinking because training involves large-scale vector updates, reductions, sorting, histogram construction, and aggregation.

For boosting, one important vectorized update is:

F(t)=F(t1)+ηft(X), F^{(t)}=F^{(t-1)}+\eta f_t(X),

where F(t)F^{(t)} is the vector of current predictions for all rows, F(t1)F^{(t-1)} is the previous prediction vector, ft(X)f_t(X) is the vector of predictions from the new tree, and η\eta is the learning rate.

A.5 Reduction operations

Boosting relies heavily on reduction operations, which compress many numbers into one number:

Gj=iIjgi,Hj=iIjhi. G_j=\sum_{i\in I_j}g_i, \qquad H_j=\sum_{i\in I_j}h_i.

If a node contains one million rows, a parallel implementation can split the work into chunks:

Gj=(iA1gi)+(iA2gi)++(iAKgi). G_j=\left(\sum_{i\in A_1}g_i\right)+\left(\sum_{i\in A_2}g_i\right)+\cdots+\left(\sum_{i\in A_K}g_i\right).

Each chunk can be computed independently. This is the basic idea behind parallel reduction.

A.6 Histogram-based boosting and massive parallelism

LightGBM and modern XGBoost implementations often use histogram-based split finding:

xi(k)bi(k). x_i^{(k)}\mapsto b_i^{(k)}.

For each feature kk and bin bb:

Gk,b=i:bi(k)=bgi,Hk,b=i:bi(k)=bhi. G_{k,b}=\sum_{i:b_i^{(k)}=b}g_i, \qquad H_{k,b}=\sum_{i:b_i^{(k)}=b}h_i.

This is highly parallelizable because different features, bins, and data partitions can be processed at the same time.

A.7 Why GPUs help

GPUs are designed for massive parallel computation. A CPU usually has fewer powerful cores, while a GPU has many smaller cores designed to perform the same type of operation across many data points.

Boosting can use GPUs effectively for:

Gradient and Hessian vector operations such as:

g=py,h=p(1p) g=p-y, \qquad h=p\odot(1-p)

are naturally suitable for GPU parallelism.

A.8 Why distributed computing helps

Distributed computing spreads computation across multiple machines. This matters when the dataset is too large for one machine or training needs to be faster.

Suppose the dataset is split across KK workers:

D=D1D2DK. D=D_1\cup D_2\cup\cdots\cup D_K.

Each worker computes local sums:

Gj(k)=iIjDkgi,Hj(k)=iIjDkhi. G_j^{(k)}=\sum_{i\in I_j\cap D_k}g_i, \qquad H_j^{(k)}=\sum_{i\in I_j\cap D_k}h_i.

Then global sums are aggregated:

Gj=k=1KGj(k),Hj=k=1KHj(k). G_j=\sum_{k=1}^{K}G_j^{(k)}, \qquad H_j=\sum_{k=1}^{K}H_j^{(k)}.

Each machine works on part of the dataset, then the partial totals are combined.

A.9 Why scalar Hessians still enable huge speedups

At first, scalar Hessians may look too simple to justify advanced computing. Their simplicity is exactly what makes them fast. For each row:

hiR. h_i\in\mathbb{R}.

For all rows:

h=[h1h2hn],g=[g1g2gn]. h=\begin{bmatrix}h_1\\h_2\\\vdots\\h_n\end{bmatrix}, \qquad g=\begin{bmatrix}g_1\\g_2\\\vdots\\g_n\end{bmatrix}.

Large vectors are ideal for vectorized computation. The algorithm does not need expensive full matrix Hessians for ordinary binary classification or regression. Instead, it uses cheap scalar second derivatives per row, then aggregates them efficiently.

A.10 Connection to split gain

Recall:

Gain=12[GL2HL+λ+GR2HR+λG2H+λ]γ. \text{Gain} =\frac{1}{2}\left[ \frac{G_L^2}{H_L+\lambda} +\frac{G_R^2}{H_R+\lambda} -\frac{G^2}{H+\lambda} \right]-\gamma.

The formula only needs aggregated values:

The algorithm does not need a full derivative structure for every row when evaluating a split. It summarizes rows into totals, then compares totals.

A.11 Difference from full matrix methods

Some machine learning methods require solving large matrix systems, such as:

(XX)1Xy, (X^\top X)^{-1}X^\top y,

or computing large Hessian matrices:

HRp×p, H\in\mathbb{R}^{p\times p},

where pp is the number of model parameters.

Boosted trees often avoid this full dense matrix operation. Instead, they rely on:

This structure is suitable for vectorization, cache-efficient CPU code, SIMD instructions, GPU kernels, distributed aggregation, and memory-efficient histogram algorithms.

A.12 Final appendix summary

The Hessian may look like “just one number” per row, but across a large dataset, those numbers become a huge vector of curvature information.

In simple terms:

one rowscalar gradient and scalar Hessian, \text{one row}\Rightarrow\text{scalar gradient and scalar Hessian},

but:

millions of rowslarge gradient and Hessian vectors. \text{millions of rows}\Rightarrow\text{large gradient and Hessian vectors}.

Large vectors can be processed quickly using:

The math is scalar per row, but the computation is massively parallel across rows, features, bins, trees, and machines. That is why XGBoost, LightGBM, and CatBoost can achieve large speedups on modern hardware.


Bibliography and Source Notes

The following references are useful for deeper study:


Closing Summary

Gradient boosting builds a strong model by adding many small correction models. XGBoost strengthens this idea with second-order optimization and explicit regularization. LightGBM makes it faster and more memory efficient through histograms, leaf-wise growth, GOSS, and EFB. CatBoost focuses on categorical variables and leakage-reducing ordered methods.

The shared foundation is:

strong model=initial guess+many small corrections. \text{strong model}=\text{initial guess}+\text{many small corrections}.

The differences are mainly about how each algorithm chooses, regularizes, accelerates, and safely computes those corrections.