Foundations to Frontier
Tests
D. Classical Machine Learning › D7 Ensemble Methods

LightGBM: Histograms, Leaf-wise Growth, GOSS and EFB

LightGBM (Ke et al., 2017) is gradient boosting engineered for speed on large data. It buckets every feature into a small number of histogram bins once, so each split search sums gradients per bin instead of scanning sorted values. It grows each tree leaf-wise, always splitting the leaf with the largest gain, rather than level by level. It also introduces two data-reduction tricks: Gradient-based One-Side Sampling (GOSS) keeps all large-gradient rows and a re-weighted sample of the rest, and Exclusive Feature Bundling (EFB) merges sparse features that are never non-zero together. This page explains each component, its accuracy and overfitting implications, and how to tune num_leaves, min_data_in_leaf and the sampling fractions. In the exercises you implement histogram splits, leaf-wise growth, GOSS and EFB; then you compare leaf-wise and level-wise growth and GOSS against uniform sampling.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Faster boosting by summarising the data

Searching every possible threshold of every feature is the slow part of boosting. LightGBM replaces each feature by, say, 255 buckets once. Finding a split then means adding up gradients per bucket, which is very fast. It also grows trees leaf-wise: instead of splitting every leaf of a level, it always splits the single leaf that promises the biggest improvement. And it trains on fewer rows (GOSS) and fewer columns (EFB) without losing much accuracy.

Leaf-wise versus level-wise tree growth
leaves 6 · share of training variance explained 86.4%
The signal sits in the upper-right corner. Leaf-wise growth keeps splitting there, because those leaves offer the largest gains, giving a deep, lopsided tree that explains more variance per leaf. Level-wise growth spends half its budget splitting flat regions that gain almost nothing. With large budgets, leaf-wise trees can grow very deep on little data, which is why LightGBM pairs them with max_depth and min_data_in_leaf limits.
Why engineers care

LightGBM trains on millions of rows in minutes on a laptop, handles categorical features natively, and is a default choice for large tabular datasets such as fleet telemetry, logs and sensor archives. Leaf-wise growth makes it accurate with few trees, but it can overfit small datasets unless num_leaves and min_data_in_leaf are set sensibly.

📝 Quick check (Level 0)
0/3 answered
  1. 1. LightGBM speeds up split finding by…
  2. 2. Leaf-wise growth splits…
  3. 3. In the demo, leaf-wise growth concentrates splits…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

The four tricks by hand

Histograms. With B = 4 bins, a feature’s values become bin indices. Summing gradients per bin, for example (1, −1, 5, 0), needs one pass. Split candidates are the B − 1 = 3 bin boundaries, with left sums 1, 0 and 5.

Histogram subtraction. After splitting a parent, build the histogram of the smaller child only. The larger child’s histogram is parent − smaller. For example (5, 3, 2) − (1, 3, 0) = (4, 0, 2).

GOSS. With a = 0.2 and b = 0.1, keep the 20% of rows with the largest |gradient| plus a random 10% of the remaining 80%. Multiply the sampled small-gradient rows’ gradients and Hessians by (1 − a)/b = 0.8/0.1 = 8, so their total contribution is unbiased. Each tree then uses 30% of the rows.

EFB. One-hot columns of a 5-level category are never non-zero in the same row, so they are mutually exclusive. Bundle them into one feature by giving each a distinct range of bin values: 5 columns become 1.

Leaf-wise growth. With a budget of 8 leaves, level-wise growth builds a full depth-3 tree. Leaf-wise growth might build depth 6 on one side if that is where the gains are. For the same number of leaves it reduces training loss at least as much (exercise 1: residual SSE 863 against 962).

The steps in plain English:

  1. Bin every feature once into at most max_bin histogram bins (255 by default), bundling exclusive sparse features.
  2. Each round, compute gradients. Optionally keep GOSS rows (large gradients plus a re-weighted sample of the rest).
  3. Grow a tree leaf-wise: for the leaf with the largest gain, split it using per-bin gradient sums, up to num_leaves (and max_depth).
  4. Add the tree with shrinkage, and repeat with early stopping.
📝 Quick check (Level 1)
0/3 answered
  1. 1. GOSS weight for sampled small-gradient rows with a = 0.2, b = 0.1?
  2. 2. Larger child's histogram by subtraction for parent (5, 3, 2) and small child (1, 3, 0)?
  3. 3. Fraction of rows per tree under GOSS with a = 0.2, b = 0.1?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Components in detail

Histogram algorithm. Pre-bin each feature (quantile-based, at most max_bin bins). For a leaf, a split search costs O(#rows) to build histograms plus O(#bins) to scan, instead of O(#rows log #rows) with sorting. Exercise 1: 32 bins recovered 97.5% of the exact best gain. Histogram subtraction halves the histogram-building work.

Leaf-wise (best-first) growth. Choose the leaf with maximal gain at each step. For the same number of leaves it lowers training loss at least as much as level-wise growth, but trees can become deep and over-specialised. Control them with num_leaves (main capacity knob, below 2^max_depth), max_depth, min_data_in_leaf and min_sum_hessian_in_leaf.

GOSS. Rows with small gradients are already well fitted and contribute little to split gains. Keep the top a·n by |g|, sample b·n of the rest, and up-weight those by (1 − a)/b. Ke et al. bound the approximation error of the estimated gain and show it is smaller than uniform sampling at the same rate when gradients are skewed.

EFB. Finding an optimal bundling is NP-hard (graph colouring), so a greedy algorithm orders features by degree in a conflict graph and allows a small conflict rate. Offsets keep the bundled features’ values distinguishable.

Categorical features use an optimal split by sorting categories by gradient statistics (like Fisher’s ordering), with smoothing and a limit on the number of categories.

import lightgbm as lgb
m = lgb.LGBMRegressor(num_leaves=31, max_depth=-1, min_child_samples=20, learning_rate=0.05, n_estimators=2000,
                      subsample=0.8, subsample_freq=1, colsample_bytree=0.8)   # data_sample_strategy="goss" for GOSS
m.fit(X_tr, y_tr, eval_set=[(X_va, y_va)], callbacks=[lgb.early_stopping(100)])
🐍 Exercise 1: histograms, leaf-wise growth, GOSS and EFB
Implement quantile binning, histogram split search with gradients and Hessians, leaf-wise versus level-wise growth with a leaf budget, GOSS sampling with re-weighting, and greedy exclusive feature bundling; verify the histogram split is close to exact, leaf-wise reduces loss at least as much, GOSS is unbiased, and one-hot columns are bundled.
📝 Quick check (Level 2)
0/3 answered
  1. 1. LightGBM's main capacity parameter is…
  2. 2. GOSS keeps all rows with…
  3. 3. Optimal feature bundling is…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Theory

Best-first growth. Given a leaf budget K, leaf-wise growth is the greedy algorithm for maximising total gain over trees with K leaves. Level-wise growth may waste splits on leaves with tiny gains. With small K, leaf-wise wins clearly (exercise 2 with 8 leaves: test MSE 0.775 against 0.984). With large K on modest data it builds very deep, specialised branches and can overfit more: at 32 leaves it was slightly worse (0.930 against 0.918).

GOSS variance. The GOSS gain estimate is unbiased for the gradient sums, and its variance is lower than uniform subsampling when most gradient mass sits in few rows (Ke et al., Theorem 3.2). Early in boosting, gradients are spread out and the advantage is small. Exercise 2 found GOSS, uniform 30% and all rows within 2% of each other: sampling 70% fewer rows cost nothing measurable here.

Histogram approximation. Quantile bins lose little because the optimal cut need only be located to within a bin of the true optimum, and split gains are smooth in the threshold over typical data. Exercise 1: 2.5% gain loss with 32 bins.

Interview questions.

  • Why does LightGBM overfit small datasets more easily than XGBoost’s defaults? Leaf-wise growth with num_leaves = 31 can produce very deep trees. On small data, lower num_leaves, set max_depth, and raise min_data_in_leaf.
  • What’s the difference between GOSS and plain subsampling? GOSS keeps all large-gradient rows and re-weights a sample of the rest, preserving the informative rows. Plain subsampling treats every row alike.
📝 Quick check (Level 3)
0/3 answered
  1. 1. With 8 leaves in exercise 2, leaf-wise growth had test MSE…
  2. 2. GOSS's advantage over uniform sampling is largest when gradients are…
  3. 3. On small data, leaf-wise trees need…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Leaf-wise growth and GOSS in practice

History.

  • Shi (2007) and Friedman used best-first trees in boosting.
  • Microsoft released LightGBM in 2016, with the NeurIPS paper in 2017 (Ke et al.).
  • The histogram method had appeared in earlier systems (SLIQ, SPRINT for decision trees; XGBoost’s “approx” and “hist” modes).
  • Native categorical support and GPU training followed.
  • LightGBM’s linear trees (2020) and CUDA versions extended it further.

Exercise 1.

  • A 32-bin histogram split recovered 97.5% of the exact best gain.
  • With 8 leaves, leaf-wise growth left residual SSE 862.9 against 962.2 for level-wise growth.
  • GOSS estimated the gradient sum without bias.
  • EFB packed 5 one-hot columns into one bundle.

Exercise 2. Setup: Friedman #1 with σ = 1, n = 1500, 32-bin histograms, ν = 0.1, 120 rounds, 2 repetitions. The table shows the best test MSE against the noise-free target.

Setting test MSE
8 leaves, leaf-wise 0.775
8 leaves, level-wise 0.984
32 leaves, leaf-wise 0.930
32 leaves, level-wise 0.918
16 leaves, all rows 0.809
16 leaves, GOSS (30% of rows) 0.806
16 leaves, uniform 30% of rows 0.797
  • With a small leaf budget, best-first growth was 21% better. It spends splits where the signal is.
  • With 32 leaves both overfit at n = 1500. The best 8-leaf model beat both 32-leaf models, and leaf-wise lost its edge.
  • Sampling 30% of rows per tree was free here. GOSS and uniform sampling tied each other and the full data within noise. GOSS’s theoretical edge needs strongly skewed gradients.
🐍 Exercise 2 (research): leaf-wise growth and GOSS
On Friedman's #1 benchmark (n = 1500, 32-bin histograms), compare leaf-wise and level-wise growth at 8 and 32 leaves, and GOSS against uniform 30% sampling and all rows (16 leaves); report best test MSE over 120 rounds (2 repetitions).

LightGBM in AI, robotics and aerospace

  • Large telemetry and log datasets: fast training and native handling of categorical fields such as unit, mode or vendor.
  • Fleet-wide predictive maintenance with millions of cycles.
  • Ranking and recommendation over mission data archives (LambdaRank objective).
  • Edge deployment: compact tree models with fast inference.

References

  1. G. Ke, Q. Meng, T. Finley, T. Wang, W. Chen, W. Ma, Q. Ye, T.-Y. Liu (2017). “LightGBM: a highly efficient gradient boosting decision tree.” NeurIPS.
  2. H. Shi (2007). “Best-first decision tree learning.” Master’s thesis, University of Waikato.
  3. T. Chen, C. Guestrin (2016). “XGBoost: a scalable tree boosting system.” KDD.
  4. M. Mehta, R. Agrawal, J. Rissanen (1996). “SLIQ: a fast scalable classifier for data mining.” EDBT.
  5. L. Prokhorenkova et al. (2018). “CatBoost: unbiased boosting with categorical features.” NeurIPS.