← All AI/ML articles

XGBoost, visualised.

Gradient boosting follows the slope of the loss. XGBoost also reads the curvature, scores every possible split with one tidy formula, and charges a price for each new leaf. See the numbers behind the most popular tabular model.

1. Slope and curvature2. Score every split3. Pay for complexity
Click to add a point of the selected class · Shift-click (or right-click) a point to remove it · Hollow dots are held out for validation · White ring = the model gets it wrong.
Train accuracy0
Validation accuracy0
Points0
Behind the scenes · 1

Slope, curvature, and leaf weights

With logistic loss, each point contributes a gradient g = p − y and a hessian h = p(1−p). The gradient shows the direction and size of the prediction error; the hessian measures the local curvature of the loss. The hessian is largest near p = 0.5 and small near probabilities 0 or 1, so dots are sized by it. A confidently wrong point has a small hessian but a large gradient, so it gets a white ring without being drawn large. Both quantities matter: a leaf’s best output is w = −G / (H + λ), using the sums over its points, and the same sums drive split gains. Slide through the rounds.


leaf pushes toward cyan (w > 0)toward pink (w < 0)ring = large gradient (badly wrong)
What the computer does in this round
Behind the scenes · 2

Scoring every split

To pick the root split of the selected tree, XGBoost tries every cut on every feature and computes Gain = ½[ GL²/(HL+λ) + GR²/(HR+λ) − G²/(H+λ) ] − γ. The curves below are that gain for each cut position. The tallest peak wins, but a split is made only if its gain is above zero and it satisfies the tree’s constraints (min child weight and max depth). γ is the minimum loss reduction a split must deliver: raise it and the whole curve sinks, so weak splits are not made.


cuts along xcuts along ygain = 0: a split must beat this

λ also lives in this formula: a bigger λ penalises large leaf weights and changes every split score. It often discourages weak splits, but it does not guarantee a smaller tree in every situation. Min child weight forbids cuts that leave a side with too little total hessian.

Behind the scenes · 3

What the brakes buy you

Solid lines use your current λ, γ and min child weight. Dashed lines use the same trees with all three set to zero. Without the brakes, training loss (cyan) dives faster, but validation loss (pink) usually turns upward sooner: the model is memorising noise.


train log-lossvalidation log-lossdashed = no regularisation
Experiment

Break it on purpose

Remove the brakes

Set λ, γ and min child weight to 0, go deep, and boost 40 rounds on noisy data.

Raise γ

Allow depth 5 but require γ = 1 of gain per split. Most weak splits are rejected and the trees stay small.

Noisy labels, held in check

Flip 10% of the labels, keep λ high, and compare validation loss with and without regularisation.

Check yourself

Three quick questions

Key takeaways

  • Second-order: XGBoost uses the gradient g and the hessian h of the loss, a Newton step instead of a plain gradient step.
  • Leaf weight w = −G/(H+λ): the best value for a leaf has a closed form. It is added to the raw score (logit), scaled by η, and the sigmoid then gives the probability.
  • Split gain compares the scores of the children with the parent, then subtracts γ: a split needs positive gain and must respect min child weight and max depth.
  • Regularisation is built into the objective: λ penalises large leaf weights, γ sets the minimum gain for a split, min child weight blocks tiny leaves.
  • Learning rate still scales every tree, so smaller steps with more rounds are usually safer.
← Back to all articles