← Back to Classic ML Mind Map
中文·English
📊 Classic MLID: xgboost-derivation

XGBoost 2nd-Order

XGBoost 二阶手推
🎯Core Definition
XGBoost is regularized second-order gradient boosting. Objective: L=∑i=1nl(yi,y^i)+∑k=1KΩ(fk)\mathcal{L} = \sum_{i=1}^{n} l\left(y_i, \hat{y}_i\right) + \sum_{k=1}^{K} \Omega(f_k) with tree regularization Ω(f)=γT+12λ∥w∥2\Omega(f) = \gamma T + \frac{1}{2} \lambda \Vert w \Vert^2 (TT leaves, ww leaf weights, γ\gamma per-leaf complexity penalty, λ\lambda L2 shrinkage on leaf weights). Round tt adds ftf_t: y^i(t)=y^i(t−1)+ft(xi)\hat{y}_i^{(t)} = \hat{y}_i^{(t-1)} + f_t(x_i); Taylor-expand the loss to second order around y^i(t−1)\hat{y}_i^{(t-1)}: l(yi,y^i(t−1)+ft(xi))≈l(yi,y^i(t−1))+gift(xi)+12hift(xi)2l\left(y_i, \hat{y}_i^{(t-1)} + f_t(x_i)\right) \approx l\left(y_i, \hat{y}_i^{(t-1)}\right) + g_i f_t(x_i) + \frac{1}{2} h_i f_t(x_i)^2 with first derivative gi=∂l(yi,y^i(t−1))∂y^i(t−1)g_i = \frac{\partial l\left(y_i, \hat{y}_i^{(t-1)}\right)}{\partial \hat{y}_i^{(t-1)}} and second derivative hi=∂2l(yi,y^i(t−1))∂(y^i(t−1))2h_i = \frac{\partial^2 l\left(y_i, \hat{y}_i^{(t-1)}\right)}{\partial \left(\hat{y}_i^{(t-1)}\right)^2}. Dropping constants, the step-tt objective is ∑i=1n[giwq(xi)+12hiwq(xi)2]+γT+12λ∑j=1Twj2\sum_{i=1}^{n} \left[ g_i w_{q(x_i)} + \frac{1}{2} h_i w_{q(x_i)}^2 \right] + \gamma T + \frac{1}{2} \lambda \sum_{j=1}^{T} w_j^2, where q(x)q(x) maps a sample to its leaf. Grouping by leaf with Ij={i∣q(xi)=j}I_j = \{ i \mid q(x_i) = j \}, Gj=∑i∈IjgiG_j = \sum_{i \in I_j} g_i, Hj=∑i∈IjhiH_j = \sum_{i \in I_j} h_i, the objective becomes ∑j=1T[Gjwj+12(Hj+λ)wj2]+γT\sum_{j=1}^{T} \left[ G_j w_j + \frac{1}{2}\left(H_j + \lambda\right) w_j^2 \right] + \gamma T — independent quadratics in each wjw_j, so the optimal leaf weight is wj∗=−GjHj+λw_j^* = -\frac{G_j}{H_j + \lambda}, giving the minimal objective L∗=−12∑j=1TGj2Hj+λ+γT\mathcal{L}^* = -\frac{1}{2} \sum_{j=1}^{T} \frac{G_j^2}{H_j + \lambda} + \gamma T. Splitting node I=IL∪IRI = I_L \cup I_R yields the structural gain Gain=12[GL2HL+λ+GR2HR+λ−(GL+GR)2HL+HR+λ]−γ\text{Gain} = \frac{1}{2} \left[ \frac{G_L^2}{H_L + \lambda} + \frac{G_R^2}{H_R + \lambda} - \frac{\left(G_L + G_R\right)^2}{H_L + H_R + \lambda} \right] - \gamma; split iff Gain>0\text{Gain} > 0 (γ\gamma acts as a minimum split gain, equivalent to post-pruning). Common losses: squared loss has gi=2(y^i−yi)g_i = 2\left(\hat{y}_i - y_i\right), hi=2h_i = 2; logistic log loss has p^i=σ(y^i)\hat{p}_i = \sigma\left(\hat{y}_i\right), gi=p^i−yig_i = \hat{p}_i - y_i, hi=p^i(1−p^i)h_i = \hat{p}_i\left(1 - \hat{p}_i\right).
💡Use Cases
whiteboard-deriving XGBoost is among the most frequently asked ML hand-derivation questions in 2026 big-tech interviews — you must write the full chain objective → second-order Taylor expansion → leaf weight → structural gain; in practice XGBoost is one of the de-facto standards for tabular data.
⚡Key Problems Solved
compared with first-order GBDT, the second-order expansion is a Newton step in function space — curvature (Hessian) information gives faster convergence and a more accurate splitting criterion (distinguishing splits with identical first-order gradients but different curvature); explicit regularization γT+12λ∥w∥2\gamma T + \frac{1}{2} \lambda \Vert w \Vert^2 folds leaf-weight shrinkage (λ\lambda) and split penalty (γ\gamma) into the objective end-to-end; engineering-wise, column subsampling, approximate quantile histograms (candidate splits drop from O(n)O(n) to O(bins)O(\text{bins})), and sparsity-aware splitting (missing values learn a default direction) make it practical on large sparse data.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of XGBoost 2nd-Order.
Use Cases
In production engineering, what are the primary use cases for XGBoost 2nd-Order and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Whiteboard XGBoost: from ∑il(yi,y^i)+∑kΩ(fk)\sum_i l(y_i, \hat{y}_i) + \sum_k \Omega(f_k), Taylor-expand to second order to get ∑i[giwq(xi)+12hiw2]+λ∥w∥2\sum_i [g_i w_{q(x_i)} + \frac{1}{2} h_i w^2] + \lambda \Vert w \Vert^2, then derive the optimal leaf weight wj∗=−GjHj+λw_j^* = -\frac{G_j}{H_j + \lambda}
2
Whiteboard the split gain Gain=12[GL2HL+λ+GR2HR+λ−(GL+GR)2HL+HR+λ]−γ\text{Gain} = \frac{1}{2}\left[\frac{G_L^2}{H_L+\lambda} + \frac{G_R^2}{H_R+\lambda} - \frac{(G_L+G_R)^2}{H_L+H_R+\lambda}\right] - \gamma: when do we not split?
3
Why second-order derivatives? Convergence advantage over first-order GBDT; what are gig_i, hih_i under squared loss and cross-entropy?
4
Roles of γ\gamma and λ\lambda: how do they affect leaf count and leaf weights? Relationship with tree pruning?
5
Engineering: exact greedy vs approximate quantile histograms, sparsity-aware splits (default direction for missing), column subsampling; differences vs LightGBM
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "XGBoost 2nd-Order"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice ➔
← Previous CardGBDT Negative GradientNext Card →LightGBM GOSS & EFB

🔗 More Classic ML Knowledge Cards

AdaBoost DerivationBagging & Random ForestBaum-Welch (HMM EM)Confusion Matrix