How is the optimal leaf weight w∗=−G/(H+λ) and the split gain derived in XGBoost's second-order objective? How do you apply it to 6 samples with logistic loss, current prediction F=0 (so p=0.5), labels 1,1,0 in the left candidate leaf and 1,0,0 in the right, λ=1, γ=0.1?

Supervised learning, XGBoost
Level L4 Advanced. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can derive the second-order leaf objective and compute a split gain with gradients and Hessians.

Key idea

Using gi=∂Fℓ and hi=∂F2ℓ, a leaf's loss is 12(H+λ)w2+Gw, with G=∑gi and H=∑hi. It is minimised at w∗=−G/(H+λ) with value −12G2/(H+λ).

Steps

  1. Expand the loss to second order around the current prediction: ℓ(yi,Fi+f(xi))≈ℓ+gif+12hif2. Add the penalty γT+12λ∑jwj2 for T leaves.
  2. Group by leaf j: the objective is ∑j[Gjwj+12(Hj+λ)wj2]+γT. Setting the derivative to zero gives wj∗=−Gj/(Hj+λ) and a leaf score of −12Gj2/(Hj+λ).
  3. The gain of a split is the old leaf score minus the new ones: Gain=12 ⁣[GL2HL+λ+GR2HR+λ−(GL+GR)2HL+HR+λ]−γ.
  4. Logistic loss: gi=pi−yi and hi=pi(1−pi). At p=0.5: hi=0.25 for all, and gi=−0.5 for label 1, +0.5 for label 0.
  5. Left (1,1,0): GL=−0.5−0.5+0.5=−0.5, HL=0.75. Right (1,0,0): GR=−0.5+0.5+0.5=0.5, HR=0.75. Parent: G=0, H=1.5.
  6. Gain =12[0.251.75+0.251.75−0]−0.1=0.1429−0.1=0.0429>0, so keep the split.
  7. Leaf weights: wL=0.5/1.75=+0.286 and wR=−0.5/1.75=−0.286 (before the learning rate). The left leaf, with mostly positives, moves the score up.

Common mistakes

How long your answer should be

One page; 7–8 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: Describe how partial least squares (PLS) builds its first component, and how it differs from principal components regression (PCR). Take centred X with X⊤X=4I2, X⊤y=(4,3)⊤ for n=4 samples: what are the first PLS direction and the one-component fit coefficients, and how do they compare with OLS?
Next in Supervised learning: A random forest has features x1 (a truly informative binary variable) and x2 (a continuous pure-noise variable). Why can mean decrease in impurity (MDI) rate x2 as important, and how does permutation importance on the out-of-bag (OOB) data fix this? What is its own weakness with correlated features?