July 2026. Math doesn't rot, but library details do - XGBoost version notes reflect 2.x-3.1.
The whole series:
- Part 1 - the Interview tier: trees, forests, and the ten core formulas
- Part 2 - the Practice tier: the knobs you actually turn (you are here)
- Part 3 - the Theory tier: full derivations and the cheat sheets
This is the practice tier of the reference: the parameters you actually turn when training tree ensembles, and the places where the intuitive reading of a knob is simply wrong. Notation and the ten core formulas live in part 1; cross-references like I.7 point there, T.7 points to part 3.
TIER 2 - [P] PRACTICE
What you actually turn, and where people actually get burned.
[P.1] The leaf value: CART, GBM (line search), XGBoost
Three different answers to "what's inside a leaf".
CART (a plain tree). Computed "automatically":
GBM (Friedman) - line search. The tree is grown by the ordinary CART criterion on pseudo-residuals, and then the leaf values are re-fitted by one-dimensional optimization inside each leaf:
XGBoost - a closed formula. , see I.7. This is the analytic solution of the same problem after the quadratic approximation.
Note [P]. Three stages of evolution: "the mean" => "one-dimensional search" => "a closed formula from Taylor". A good answer to "how does XGBoost differ from GBM".
Trap. For reg:absoluteerror (MAE) and quantile regression the hessian is constant, the Newton step degenerates => XGBoost uses adaptive trees: it builds the structure, then recomputes the leaf values as the median (or the quantile). In other words, it falls back to line-search logic.
[P.2] Learning rate (shrinkage)
Role. Shrinking each tree's contribution leaves "room" for the following ones. A form of regularization.
The trade-off. and the number of trees trade against each other: roughly for comparable fit. Smaller + larger => better generalization, longer training.
Practice. ; the number of rounds is decided by early stopping, not by hand.
Note [P]. The standard recipe: fix , tune everything else, then at the end cut by 2-4x and raise the round cap proportionally.
[P.3] min_child_weight is NOT a sample count
The / table by objective (memorize):
| Objective | What min_child_weight means |
||
|---|---|---|---|
reg:squarederror,
|
number of samples in the leaf | ||
binary:logistic |
total uncertainty | ||
count:poisson (log link) |
sum of expected intensities | ||
reg:absoluteerror |
number of samples |
The intuition-breaking consequence. In binary classification, a leaf of ten confident samples ( or , ) has a tiny and will be rejected. A leaf of three borderline samples ( , ) gives and may pass. The parameter doesn't say "few samples" - it says "not enough reliable information".
Scaling. grows with data size => the default of 1 restricts almost nothing at a million rows. Tune it with in mind.
Note [P]. A top-3 XGBoost trap question. Plenty of people confidently answer "minimum number of samples in a leaf" - true only for MSE.
[P.4] max_delta_step
Why. Under extreme imbalance in logistic tasks , the denominator is tiny => the leaf weight blows up => unstable updates. A hard cap (typically 1-10) makes the step conservative.
Note [P]. The standard recommendation for heavily imbalanced binary classification, together with scale_pos_weight P.10. Default 0 = no cap.
[P.5] Cost-complexity pruning and the number of leaves
Classic CART (post-pruning):
Symbols. - the tree's training error; - the number of leaves; - the price of one leaf. As grows, the optimal subtree shrinks (a nested sequence of subtrees exists).
XGBoost - the same idea, but inside the objective:
Here plays the role of CART's .
How relates to splits. A binary split turns one leaf into two: . Hence the local price of a split I.8.
Step by step: how XGBoost actually prunes.
- Grow the tree to
max_depth(depthwise). - Walk bottom-up and prune nodes with .
Why post-pruning rather than greedy stopping. A split can be bad on its own ( ) yet open the path to an excellent split below it. Greedy stopping would miss that.
Note [P]. max_depth is a ceiling, not a target depth. Trees come out asymmetric: one branch deep, another cut early. Late trees in a boosting run are usually shallower (gradients are smaller => Gain hits zero sooner).
[P.6] max_features / mtry - the heuristics
Symbols. - total features, - features considered at each split.
Where from. Empirical recommendations (Breiman, ESL). This is the lever from I.3: smaller => more diverse trees => lower correlation => lower variance floor; but each tree is weaker (higher bias). The classic trade-off.
The XGBoost analogue - three levels that multiply:
With all three at 0.5, a node sees roughly features.
Note [P]. Tying max_features to formula I.3 is a strong move. Not "we add randomness" but "we lower
to push down the variance floor".
[P.7] Bootstrap size and subsample
Bagging/RF: sampling with replacement, size (by default). Hence 0.632 / 0.368 I.4.
Boosting (subsample): sampling without replacement, a fraction 0.5-1.0. This is stochastic gradient boosting (Friedman).
Note [P]. The with/without-replacement distinction is a detail people mix up constantly. Bagging needs replacement to get different same-size samples; boosting just takes a fraction of the rows.
[P.8] Feature importance: the formulas and their biases
MDI (mean decrease in impurity), a.k.a. gain in XGBoost:
Symbols. - the impurity decrease (or Gain) at node ; - the share of samples passing through the node (coverage weighting).
Importance types in XGBoost:
| Type | Formula / meaning |
|---|---|
weight |
how many times the feature was used in splits |
gain |
average Gain over that feature's splits |
cover |
average hessian sum in nodes using the feature |
total_gain, total_cover
|
totals rather than averages |
Permutation importance:
The biases (must know).
- MDI is biased toward high-cardinality features: more candidate thresholds => more chances to stumble on a good split I.2.
- Correlated features split the credit: the tree picks one, the other gets zero.
- Permutation breaks under correlation: shuffling creates unrealistic samples outside the data's support.
-
An API trap:
Booster.get_score()defaults toweight, while the sklearn wrapper'sfeature_importances_in modern versions defaults togain. One model, different rankings. Always setimportance_typeexplicitly.
The main warning. Feature importance is not a causal effect. The model exploits any association, proxy, or confounder. It's the same trap as confounding in statistical inference, wearing an importance costume.
Where else it shows up. Direct parallel: a regression coefficient on observational data is an association, not an effect.
[P.9] Metrics: what measures what
ROC-AUC (the interpretation that matters):
That is the probability that a randomly chosen positive scores higher than a randomly chosen negative. Equivalent to the normalized Mann-Whitney statistic:
Symbols. - the model's score; - the number of positives and negatives.
Consequence. AUC depends only on the ordering, not the score values. Therefore monotone calibration does not change AUC. An excellent interview fact.
Brier score (calibration + discrimination):
Literally MSE on probabilities. A proper scoring rule.
Log-loss:
Which when.
- you need ranking => ROC-AUC; under heavy imbalance PR-AUC is more honest;
- you need probabilities => log-loss, Brier, calibration curves.
Note [P]. Discrimination and calibration are different qualities. A model can rank perfectly (AUC = 0.95) and lie in its probabilities. If decisions are made at a monetary threshold - calibration is mandatory.
Calibration of tree models.
- Random Forest - typically under-confident (averaging pulls probabilities toward the middle).
- Boosting on log-loss - typically over-confident (pushes toward 0 and 1). Treatment: Platt scaling (a logistic layer on top of the score) or isotonic regression, on a separate set.
[P.10] scale_pos_weight and the base-rate shift
where
is scale_pos_weight.
What it does. Re-weights the positive class by multiplying its gradients and hessians.
What it breaks. Calibration. Exactly like undersampling: it shifts the base rate, so the predicted probabilities stop matching the real-world frequency.
How to choose.
- you need ranking (top-N for manual review) =>
scale_pos_weightis fine, calibration irrelevant; - you need probabilities (threshold decisions in money) => better not to re-weight and tune the threshold instead; or re-weight and then calibrate.
Where else it shows up. The same story as "negative sampling breaks calibration": sampling/re-weighting moves the intercept (base rate), not the slopes. For inference (coefficients, odds ratios) it's nearly harmless; for prediction with probabilities it's critical.
[P.11] Histogram subtraction
The idea. Build the histogram only for the smaller child; get the bigger one by subtraction. Nearly a 2x saving.
Where else it shows up. A standard trick in every histogram-based booster (XGBoost hist, LightGBM).
Note [P]. A good "engineering" fact - shows you've read beyond the math.
[P.12] Weighted quantile sketch: why the quantiles are hessian-weighted
Define the rank function for feature :
Candidate thresholds are chosen so that
Symbols.
- pairs of (feature value, hessian);
- the precision (sketch_eps).
Why the weights are exactly . Because after Taylor the objective is equivalent to a weighted least squares with weights T.7. So a sample's importance for threshold selection is proportional to its hessian. The grid is built so that the total per bucket is equal, not the sample count.
Sanity check on MSE. => weighted quantiles degenerate into ordinary ones. A special case, again.
Note [P]. "Why are the quantiles weighted?" is a marker question separating people who read the paper from people who read a blog post.
That was the practice tier. If one of these knobs just explained a bug you shipped last month - you know which reaction button to press ;)
New deep-dives (plus the provider discounts and free tiers I run into) land on my Telegram first: FitHappensML. Or catch me on X / Threads - ML/DS folks and app builders get a follow back.
Next up, part 3: the full derivations behind all of this, plus the cheat-sheet appendices - Part 3 - the Theory tier: full derivations and the cheat sheets

Top comments (0)