What do the gradient g_i and hessian h_i represent in XGBoost's objective?

Quick Overview

Asks what the per-sample gradient and hessian mean in the XGBoost objective and how the tree builder uses them. Tests the second-order expansion of the loss, the leaf weight and split gain formulas, and what a custom objective must return.

What do the gradient g_i and hessian h_i represent in XGBoost's objective?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: hard

Interview Round: Other

What do the gradient `g_i` and hessian `h_i` represent in `XGBoost`'s objective? Both quantities appear in the approximation of the loss that XGBoost uses when it builds each new tree. ```hint Expand the loss Write the loss for one sample as a function of the current prediction and expand it to second order around that point. ``` ```hint Follow the sums Once the expansion is grouped by leaf, the best value for each leaf has a closed form. Look at which sums of the two per-sample quantities appear in it and in the split score. ``` ### What a Strong Answer Covers - What the two quantities are mathematically, and which variable they are differentiated with respect to - Their values for squared error and logistic loss, and what those values mean - How they come out of the second-order expansion of the objective - How their per-leaf sums give the leaf weights and the split gain - Where the hessian appears elsewhere in the algorithm, and what a custom objective must return ### Follow-up Questions - Why does XGBoost use a second-order expansion, when classic gradient boosting fits only the negative gradient? - What happens to a leaf weight when the leaf's hessian sum is close to zero, and which parameters guard against it? - How would you write a custom objective for a loss whose second derivative is zero or negative? - Why does `min_child_weight = 1` mean something different for regression and for binary classification?

Overview: Asks what the per-sample gradient and hessian mean in the XGBoost objective and how the tree builder uses them. Tests the second-order expansion of the loss, the leaf weight and split gain formulas, and what a custom objective must return.

General logo
General
Nov 24, 2026
hardMachine Learning EngineerOtherMachine Learning
0
0

What do the gradient g_i and hessian h_i represent in XGBoost's objective?

Both quantities appear in the approximation of the loss that XGBoost uses when it builds each new tree.

What a Strong Answer Covers Guidance

  • What the two quantities are mathematically, and which variable they are differentiated with respect to
  • Their values for squared error and logistic loss, and what those values mean
  • How they come out of the second-order expansion of the objective
  • How their per-leaf sums give the leaf weights and the split gain
  • Where the hessian appears elsewhere in the algorithm, and what a custom objective must return

Follow-up Questions Guidance

  • Why does XGBoost use a second-order expansion, when classic gradient boosting fits only the negative gradient?
  • What happens to a leaf weight when the leaf's hessian sum is close to zero, and which parameters guard against it?
  • How would you write a custom objective for a loss whose second derivative is zero or negative?
  • Why does min_child_weight = 1 mean something different for regression and for binary classification?