XGBoost, LightGBM & CatBoost
Use modern GBDT libraries with regularization, categorical handling, and speed tricks.
In plain words
These are three fast, popular tools for building boosted trees; each has tricks that make it quicker, simpler or better at certain kinds of data.
Think of it like…
Three kitchens making the same dish: one cooks in strict layers (XGBoost), one always works on the pot that's closest to done (LightGBM), and one prepares ingredients in a way that never lets the answer sneak into the recipe (CatBoost).
Where you’ve seen it
XGBoost's split gain with L2 penalty λ = 1 and complexity penalty γ = 1 is Gain = ½[G_L²/(H_L + λ) + G_R²/(H_R + λ) − (G_L + G_R)²/(H_L + H_R + λ)] − γ. For a candidate split with G_L = −6, H_L = 4, G_R = 5, H_R = 6: G_L²/(H_L + λ) = 36/5 = 7.2, G_R²/(H_R + λ) = 25/7 = 3.571, and the unsplit parent term is (−1)²/11 = 0.091, so Gain = ½(7.2 + 3.571 − 0.091) − 1 = 4.34 > 0 and the split is kept; the optimal leaf values are w = −G/(H + λ) = 1.2 on the left and −0.714 on the right. On a 5-million-row, 100-feature click dataset the team compares libraries with tree_method='hist' for XGBoost, default LightGBM and CatBoost with its native categorical columns; all reach AUC within 0.003 of each other after tuning, but LightGBM trains fastest on CPU, CatBoost needs the least tuning for the 12 high-cardinality categorical features (user, device, campaign), and XGBoost integrates best with their serving stack.
Words you’ll hear
- Gain and Hessian
- Split quality computed from summed gradients G and curvatures H of the loss.
- Histogram-based splitting
- Bucketing feature values into about 255 bins so split search scans bins, not rows.
- Leaf-wise vs level-wise growth
- Splitting the best leaf anywhere versus splitting every node at a depth.
- Ordered target statistics
- Encoding a category using only earlier rows to avoid target leakage.
Visual diagram
Theory & deep dive
The shared objective and XGBoost's split gain
All three optimise a regularised objective approximated by a second-order Taylor expansion: for each row they compute the gradient gᵢ and Hessian hᵢ of the loss with respect to the current prediction (squared error: g = pred − y, h = 1; log-loss: g = p − y, h = p(1 − p)). For a leaf containing rows I, the optimal leaf weight is w* = −Σg / (Σh + λ), and the leaf's contribution to the objective is −½ (Σg)² / (Σh + λ) + γ. The gain of splitting a node is the improvement in this score: ½[G_L²/(H_L + λ) + G_R²/(H_R + λ) − (G_L + G_R)²/(H_L + H_R + λ)] − γ, where γ is a per-leaf complexity penalty and λ shrinks leaf weights. A split is kept only if the gain is positive, so γ (gamma/min_split_gain) and min_child_weight (minimum Hessian sum per leaf) prune weak splits.
With the example numbers (G_L = −6, H_L = 4, G_R = 5, H_R = 6, λ = 1, γ = 1) the gain is ½(7.2 + 3.571 − 0.091) − 1 = 4.34, and the leaf weights are 6/5 = 1.2 and −5/7 = −0.714. Using Hessians makes updates Newton-like and lets the same machinery handle many losses; shrinkage (learning_rate) scales each tree. Beyond this core, libraries add column and row subsampling, L1/L2 regularisation, monotonic constraints, interaction constraints, custom objectives and native handling of missing values (learned default direction at each split).
G_L = −6, H_L = 4; G_R = 5, H_R = 6; λ = 1; γ = 1. Left term 36/5 = 7.2; right 25/7 = 3.571; parent (−1)²/11 = 0.091. Gain = 0.5 × (7.2 + 3.571 − 0.091) − 1 = 4.34. Leaf weights: left 6/5 = 1.2, right −5/7 = −0.714.
What differs: growth, speed and categoricals
XGBoost grows trees level-wise (depth-wise) up to max_depth, with exact or histogram split finding (tree_method="hist", the default in recent versions), sparse-aware handling and GPU support; tune max_depth, min_child_weight, subsample, colsample_bytree, reg_lambda, learning_rate and use early_stopping_rounds. LightGBM bins each feature into at most 255 buckets (max_bin) so split search scans bins instead of every distinct value; it grows leaf-wise (the leaf with the largest gain is split next), which reaches lower loss with fewer splits but can overfit on small data, so control num_leaves (keep below 2^max_depth), min_data_in_leaf and max_depth. It adds GOSS (keep large-gradient rows, sample small-gradient ones) and EFB (bundle mutually exclusive sparse features), making it very fast on millions of rows. It treats categoricals natively by sorting category statistics, which can overfit high-cardinality features without regularisation (cat_smooth, min_data_per_group).
CatBoost is designed around categorical features and prediction bias. Ordered target statistics encode a category using only rows that precede it in a random permutation (so a row's own label never leaks into its encoding) and ordered boosting avoids target leakage in gradient estimates; it builds symmetric (oblivious) trees (the same split at every node of a level), which are regularising and very fast to evaluate at inference. It often gives strong results with default parameters and handles text and embeddings. Practical guidance: use LightGBM when data is large and you need speed, CatBoost when you have many high-cardinality categoricals or little tuning budget, XGBoost for a mature ecosystem and flexibility, and benchmark all three on your data. Avoid manual target encoding outside a proper out-of-fold scheme because it leaks labels, and always evaluate with leakage-safe splits.
A numeric feature with 10 million distinct values would need up to 10 million candidate thresholds per split in an exact method. With 255 bins the algorithm builds one histogram of gradient sums in a pass and scans 255 candidates, and a child's histogram can be derived by subtracting its sibling from the parent, roughly halving the work.
How it works, step by step
Step 1 of 41. Baseline and prepare data
Fit a random forest or logistic baseline; split without leakage; keep categoricals as raw categories where supported.
- Missing values
- handled natively
When to use it & trade-offs
What it is
XGBoost, LightGBM and CatBoost are the three production-grade implementations of gradient-boosted decision trees (GBDT). All use second-order (gradient and Hessian) information and regularised objectives; they differ in how they grow trees and handle data. XGBoost grows trees level by level with a regularised gain, supports sparse data and has the broadest ecosystem. LightGBM uses histogram binning and leaf-wise growth (splitting the leaf with the largest gain), plus sampling and feature-bundling tricks, to train very fast on large data. CatBoost uses ordered boosting and ordered target statistics to encode categorical features without target leakage and builds symmetric (oblivious) trees that are fast at inference and strong with default settings.
Why it matters: On structured tabular data these libraries are usually the first choice for accuracy, and each has a distinctive strength: LightGBM for speed on millions of rows, CatBoost for categorical-heavy data with minimal tuning, XGBoost for maturity and flexibility. Knowing the gain formula, why histograms speed things up and how categorical handling can leak the target is what separates tuning with understanding from random searching.
When to reach for it
- Tabular classification, regression and ranking in production
- Datasets with many categorical or missing values
- Competitions and high-accuracy scoring models
When to avoid or be careful
- Hand-made target encoding without out-of-fold splits
- Leaf-wise growth with no limit on num_leaves for small data
- Comparing libraries with different early-stopping setups
XGBoost vs LightGBM vs CatBoost
Strengths: Robust, GPU and distributed support, many options.
Watch out: Slower than LightGBM on very large data; no native ordered categoricals.
Strengths: Histogram plus leaf-wise growth; GOSS and EFB.
Watch out: Leaf-wise growth can overfit small data.
Strengths: Ordered target statistics; strong defaults; fast inference.
Watch out: Slower CPU training; fewer low-level knobs.
Interview signals & numbers to know
When this topic comes up
- “Which GBDT library should we use?”
- Histogram-based splitting
- Ordered target statistics
- Leaf-wise growth
- min_child_weight
Benchmarks & rules of thumb
- 255
- default maximum bins per feature in LightGBM
- 4.34
- split gain in the worked example (λ = 1, γ = 1)
- −G/(H + λ)
- optimal leaf weight
Common mistakes & follow-ups
Common interview mistakes
- Setting num_leaves to 255 with max_depth 6.
- Target-encoding categories on the full dataset before splitting.
- Choosing a library from one benchmark on a different data shape.
Likely interviewer follow-ups
- What is the difference between level-wise and leaf-wise tree growth?
- How does CatBoost avoid target leakage for categoricals?
- Why does histogram splitting speed up training?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply XGBoost, LightGBM & CatBoost with data science interview Q&A and hands-on practice.