Formula used
Soft threshold: T(G, α) = sign(G) × max(|G| − α, 0)
Node score: Score = T(G, α)² ÷ (H + λ)
Raw gain: ½ × [Score(left) + Score(right) − Score(parent)]
Final gain: Raw gain − γ
Leaf weight: w* = −T(G, α) ÷ (H + λ)
How to use
- Enter parent gradient and Hessian totals.
- Enter left, right, and missing statistics.
- Choose lambda, gamma, alpha, and minimum child weight.
- Add candidate thresholds for comparison.
- Select Calculate gain to rank every valid split.
- Review gain, weights, warnings, charts, and missing direction.
- Copy, print, or download the result.
Example data
| Scenario | Parent G | Parent H | Left G | Left H | Right G | Right H | Purpose |
|---|---|---|---|---|---|---|---|
| Binary classification | -8 | 20 | -6 | 8 | -1 | 10 | Compare a useful classification split. |
| Regression | 14 | 30 | 11 | 12 | 3 | 18 | Measure squared-error objective improvement. |
| Rejected split | 2 | 15 | 1 | 7 | 1 | 8 | Show a low-gain candidate. |
| Strong regularisation | -25 | 40 | -18 | 19 | -7 | 21 | Inspect lambda and alpha effects. |
Understanding the result
Positive final gain means the split improves the regularised objective. Zero gain means the split adds no measurable improvement. Negative gain normally means the split should be rejected.
Lambda reduces extreme node scores and leaf weights. Alpha removes weak gradient contributions through soft thresholding. Gamma requires enough improvement before a split is accepted.
Minimum child weight checks each child Hessian total. Missing values are tested in both directions. The calculator selects the direction producing higher final gain.
Frequently asked questions
What does XGBoost gain measure?
Gain measures objective improvement from creating two child nodes. It compares child scores against the parent score. Regularisation penalties reduce the final value.
Why is the Hessian required?
The Hessian represents second-order curvature information. It stabilises score and weight calculations. Larger Hessians usually reduce extreme updates.
What does lambda change?
Lambda adds L2 regularisation to every denominator. Higher values shrink leaf weights. They may also reduce split gain.
What does alpha change?
Alpha applies L1 regularisation to gradients. Small gradients may become zero. This encourages simpler and sparser updates.
What does gamma change?
Gamma is subtracted from raw split gain. It discourages weak tree growth. A split must exceed this penalty.
Why compare missing directions?
XGBoost can learn a default path for missing values. Each direction produces different child statistics. The better gain becomes the preferred path.
When is a split accepted?
The final gain should be positive. Both children should satisfy minimum child weight. Input statistics must also remain valid.
Can regression gradients be used?
Yes, custom regression gradients and Hessians are supported. Enter their sums for each node. The gain formula remains objective based.
Why might totals not match?
Parent statistics should equal left, right, and missing totals. Rounding may create small differences. Large differences usually indicate input mistakes.