Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Boosting with a precise score for every split
Plain gradient boosting fits a tree to the gradients, then fixes up the leaf values. XGBoost asks directly: how much would this split lower the regularised loss? Using both the slope (gradient) and the curvature (Hessian) of the loss, it scores every candidate split with one formula. It charges a price γ for each new leaf and shrinks leaf values with λ. A split happens only if its gain beats its price.
XGBoost won a large share of machine-learning competitions after 2015 and is still a standard tool for tabular problems in industry: fault prediction, demand forecasting, risk models. Knowing what λ, γ, min_child_weight, eta and subsample do lets you tune it deliberately, and its built-in missing-value handling suits telemetry with gaps.
- 1. XGBoost scores splits using…
- 2. γ in XGBoost is…
- 3. In the demo, raising λ…
Level 1: Beginner
★★☆☆☆ Basic⏱ 30 minSecondary-school mathematics: arithmetic and elementary algebra.Leaf weights and split gain by hand
Leaf weight. For a leaf with gradient sum G = 4 and Hessian sum H = 2, with λ = 2:
w* = −G/(H + λ) = −4/4 = −1. With λ = 0 it would be −2: λ shrinks the step.
Leaf objective. At the optimum, G·w + ½(H + λ)w² equals −½G²/(H + λ) = −½·16/4 = −2.
Split gain. A node has G = 0 and H = 4. A split gives a left side with G_L = −3, H_L = 2 and a right side with G_R = 3, H_R = 2. With λ = 1:
gain = ½[9/3 + 9/3 − 0/5] − γ = 3 − γ.
With γ = 3.5 the gain is −0.5, so XGBoost does not split.
Missing values. Suppose the rows with this feature missing have G_m = 2 and H_m = 1. XGBoost evaluates the split twice, with those rows added to the left side and with them added to the right side. The side giving the larger gain becomes the learned default direction for missing values at that node.
The steps in plain English:
- Compute each example’s gradient gᵢ and Hessian hᵢ of the loss at the current predictions (for log loss: p − y and p(1 − p)).
- Grow a tree greedily. For each candidate split, compute the gain from the G and H sums, trying missing values on both sides.
- Split only if the best gain is above 0 (it already subtracts γ) and both children have H ≥ min_child_weight.
- Set leaf weights to −G/(H + λ), add η times the tree, and repeat. Stop early on validation loss.
- 1. Leaf weight for G = 6, H = 1, λ = 2?
- 2. Gain 3 − γ with γ = 3.5 means…
- 3. Default directions for missing values are…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.Derivation
Regularised objective at round t. Minimise Obj = Σᵢ L(yᵢ, F_(t−1)(xᵢ) + f(xᵢ)) + Ω(f), where Ω(f) = γT + ½λ Σⱼ wⱼ² (+ α Σⱼ |wⱼ|) for a tree f with T leaves and weights w.
Second-order expansion. Obj ≈ Σᵢ [gᵢ f(xᵢ) + ½hᵢ f(xᵢ)²] + Ω(f) + constant, with gᵢ = ∂L/∂F and hᵢ = ∂²L/∂F². Group the examples by leaf, with G_j = Σ over leaf j of gᵢ and H_j = Σ over leaf j of hᵢ:
Obj = Σⱼ [G_j w_j + ½(H_j + λ)w_j²] + γT.
Optimal weights. Each leaf’s term is a quadratic in w_j, minimised at w_j* = −G_j/(H_j + λ), with value −½G_j²/(H_j + λ). The structure score of the whole tree is −½ Σⱼ G_j²/(H_j + λ) + γT.
Split gain. The objective before a split minus the objective after it:
Gain = ½[G_L²/(H_L + λ) + G_R²/(H_R + λ) − (G_L + G_R)²/(H_L + H_R + λ)] − γ.
Regularisers.
| Parameter | effect |
|---|---|
| λ (reg_lambda) | shrinks leaf weights; stabilises leaves with small H |
| α (reg_alpha) | L1 on weights: soft-thresholds G, can zero leaves |
| γ (min_split_loss) | minimum gain to split: pre-pruning |
| min_child_weight | minimum H in a child (for log loss, about p(1 − p) × count) |
| η (eta) | shrinkage |
| subsample, colsample_* | row and column sampling |
| max_depth / max_leaves | tree size |
Systems.
- Exact greedy enumeration over presorted feature blocks.
- An approximate algorithm with a weighted quantile sketch: candidate cuts at quantiles weighted by hᵢ.
- Sparsity-aware split finding that visits only non-missing entries.
- Cache-aware access, out-of-core blocks, and GPU and histogram (“hist”) modes.
import xgboost as xgb
clf = xgb.XGBClassifier(n_estimators=2000, learning_rate=0.05, max_depth=4, reg_lambda=1.0, gamma=0.0,
min_child_weight=1, subsample=0.8, colsample_bytree=0.8, tree_method="hist",
early_stopping_rounds=50).fit(X_tr, y_tr, eval_set=[(X_va, y_va)])- 1. The optimal leaf weight minimises…
- 2. min_child_weight constrains each child's…
- 3. The weighted quantile sketch weights points by…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory
Newton boosting. Using hᵢ makes each tree a Newton step in function space rather than a gradient step. For log loss, low-curvature points (p near 0 or 1, already confidently classified) contribute little to leaf values, so steps are larger where the model is uncertain. Convergence in rounds is faster. Exercise 2: Newton boosting reached its best log loss in about 50 rounds, against 120+ for first-order boosting with the same learning rate.
But faster also means overfitting sooner. Without λ or γ, the Newton model’s test log loss rose from 0.443 to 0.532 by round 120. λ = 1 softened this, and γ = 1 pruned trees to 2–3 leaves and stayed stable. λ = 10 with γ = 1 underfit (0.509).
The role of λ in leaves with tiny H. In a nearly pure leaf, H = Σp(1 − p) is small, so −G/H can be huge (an overconfident step). λ caps such steps. That is one reason XGBoost’s default λ = 1 matters more for classification than regression.
Interview questions.
- Explain XGBoost’s split gain formula. It is the reduction in the regularised second-order objective: the children’s structure scores minus the parent’s, minus the leaf price γ.
- How does XGBoost handle missing values? Each split learns a default direction by trying missing rows on both sides during split finding and keeping the better side, at no extra cost thanks to sparsity-aware enumeration.
- 1. Newton boosting converges in fewer rounds because…
- 2. λ is especially important when a leaf's H is…
- 3. In exercise 2, γ = 1 produced trees with about…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.First-order versus Newton, and how much regularisation
History.
- Chen and Guestrin (2016) published XGBoost in KDD, after the system’s success in the Higgs boson challenge (2014).
- Its ideas came from Friedman’s work and from LambdaMART-style second-order boosting (Li, 2010).
- GPU and histogram methods followed (2017).
- LightGBM (2017) and CatBoost (2018) emerged as competitors with different split and sampling strategies.
Exercise 1.
- The leaf weight and split gain matched the second-order objective.
- γ = 20 cut the tree from 8 leaves to 2, and λ = 50 shrank a leaf weight from −1.404 to −0.716.
- With x₀ missing exactly when it is high, the root learned “missing → right”.
- 30 rounds reached training accuracy 0.968.
Exercise 2. Setup: the 10-D sphere problem, n = 600 with 10% flipped labels, depth-4 trees, η = 0.3, 120 rounds, 2 repetitions. The table shows clean test log loss.
| Variant | best (round) | final | leaves per tree |
|---|---|---|---|
| first-order (Hessian = 1) | 0.469 (120) | 0.469 | 14.8 |
| Newton, λ = 0 | 0.443 (51) | 0.532 | 14.5 |
| Newton, λ = 1 | 0.458 (48) | 0.502 | 13.5 |
| Newton, λ = 1, γ = 1 | 0.464 (113) | 0.464 | 2.4 |
| Newton, λ = 10, γ = 1 | 0.509 (119) | 0.509 | 2.0 |
- Newton steps reached the lowest log loss in less than half the rounds, but then overfit the noisy labels.
- λ reduced the late overfitting. γ turned the trees into near-stumps that never overfit within 120 rounds, at a slightly worse best value.
- Strong λ with γ underfit.
- Lesson: XGBoost’s power comes with knobs. Pair Newton boosting with early stopping and moderate λ and γ.
XGBoost in AI, robotics and aerospace
- Predictive maintenance and failure-risk scoring from fleet telemetry, with missing sensor readings handled natively.
- Anomaly and event classification in operations data.
- Learning-to-rank (LambdaMART objective) for search over mission data archives.
- Fast inference: compiled tree ensembles run in microseconds on embedded CPUs.
References
- T. Chen, C. Guestrin (2016). “XGBoost: a scalable tree boosting system.” KDD.
- J. H. Friedman (2001). “Greedy function approximation: a gradient boosting machine.” Annals of Statistics 29(5).
- P. Li (2010). “Robust LogitBoost and adaptive base class (ABC) LogitBoost.” UAI.
- C. J. C. Burges (2010). “From RankNet to LambdaRank to LambdaMART: an overview.” Microsoft Research Technical Report MSR-TR-2010-82.
- V. Borisov et al. (2022). “Deep neural networks and tabular data: a survey.” IEEE TNNLS.