← All AI/ML articles

LightGBM, visualised.

Same boosting idea, built for speed. LightGBM groups values into a few bins, grows each tree by always splitting the most promising leaf, and trains on only the rows that still have something to teach. Each trick is shown next to the classic way.

1. Bin the values2. Grow leaf-wise3. Sample by gradient
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
Rows used / tree0
Behind the scenes · 1

Histograms instead of sorting

The classic method sorts every feature and tests a cut between every pair of neighbouring values. LightGBM first drops each value into one of a few bins (once, before training). Then a node only needs to add up the gradients G and hessians H per bin, and test bins − 1 cuts. Bars show G per bin (above zero: leans pink, below: leans cyan); the white line is the gain of cutting after each bin.


bin pulls toward cyan (G < 0)bin pulls toward pink (G > 0)gain of cutting after the bin

Fewer bins means faster and smoother, but cuts can only land on bin edges (switch on Show bin edges above). More bins means finer cuts but more work. A sensible default (255) is almost lossless on big data; here the data is tiny, so try 3 to see the blockiness.

Behind the scenes · 2

Leaf-wise vs level-wise growth

A level-wise tree splits every leaf on a level before going deeper. A leaf-wise tree always splits whichever leaf offers the biggest gain, wherever it is. Both trees below use the same data, the same gradients and the same budget of num leaves. Numbers on the nodes show the order of the splits.


leaf pushes toward cyanleaf pushes toward pinknumber = order of split

Leaf-wise growth reduces the loss faster for the same number of leaves, but it can grow long lopsided branches that chase a few points. That is why num leaves and min data in leaf are the main brakes in LightGBM.

Behind the scenes · 3

GOSS: learn from the rows that still hurt

Points the model already gets right have tiny gradients and little to teach. Gradient-based One-Side Sampling keeps the top a% of all rows by |gradient|, then randomly picks another b% of all rows from the remaining small-gradient ones (so the sample size is b × N, not b × the remainder). Those sampled rows are multiplied by (1−a)/b so the totals stay fair. Fewer rows, almost the same signal.


kept (top gradients)sampled, then up-weighteddropped this round
What GOSS does in this round
train log-lossvalidation log-lossdashed = all rows (no GOSS)
Experiment

Break it on purpose

Too few bins

Only 3 bins per feature. Cuts can only land on 2 edges, so the boundary turns blocky.

Leaf-wise run-away

16 leaves, no L2 penalty, min data 1, noisy data. Watch validation loss climb as branches chase single points.

Squeeze with GOSS

Keep only the top 10% of rows by gradient and sample another 5% of all rows from the rest. How little data can a tree live on?

Check yourself

Three quick questions

Key takeaways

  • Histogram binning: values are bucketed once, then each node scans a handful of bins instead of every unique value.
  • Leaf-wise growth: always split the leaf with the best gain. Faster loss reduction, but needs num leaves and min data in leaf to stay in check.
  • GOSS: keep the top a% of rows by gradient, sample b% of all rows from the rest and up-weight them by (1−a)/b.
  • Same maths underneath: gradients, hessians, gain and leaf weights work as in XGBoost. The speed comes from the engineering.
  • Another trick, not shown here: Exclusive Feature Bundling merges sparse features that are never non-zero together.
← Back to all articles