learn-ensemble-methods-with-phoebe / Session 5 of 6
Learn Ensemble Methods with Phoebe · Session 5 of 6

LightGBM & CatBoost

XGBoost is the residual loop plus regularization plus engineering - session 4's whole story. Tonight the other two engines that win competitions today: LightGBM, which asked "what can we skip and still find the same splits?" and answered with histograms, GOSS and EFB; and CatBoost, which found a leak hiding in how everyone was encoding categories - a feature that quietly contains the answer - and rebuilt the training order to close it. By the end you can pick the right engine for a job and defend the pick with quotes, not vibes.

🟠 Hands-on Builders - you drove the loop in session 3 45 min
0-3 · Welcome 3-22 · Speed tricks and the leak 22-40 · Build-along: pick the engine for the job 40-45 · Q&A
Part 0

Two engines, two different bets

Session 4 left you with an engine that prices complexity: gamma per leaf, lambda on weights, second-order gain, early stopping as a parameter. LightGBM and CatBoost do not replace any of that. LightGBM's bet is speed - approximate the split search aggressively and spend the saved time on more data. CatBoost's bet is categorical features - and while making it, its authors documented a subtle leak worth an entire section of tonight, because it bites anyone who target-encodes a category by hand, whatever library they run.

🎫 Clear all three quiz questions to stamp your passport Live = presented in the 45 minutes Self-study = the full depth, after class

★ What you walk out with tonight. LightGBM's three speed tricks with their exact scopes, including the 20x claim quoted against the right baseline. The target leak computed by hand on five rows, so you can never unsee it. And a one-table decision guide for choosing between the three engines that you can defend in a design review.

LiveSame family, different bets3 min▶

All three engines run session 3's loop: score everyone, fit a small tree to the gradients, add it scaled, repeat, stop early. Nothing tonight touches that core. What differs is how they search for splits - exactly, over histograms, or over a gradient-filtered subsample - and how they treat categories - as numbers you encode yourself, or as first-class citizens with leak protection built in.

Hold onto that framing, because marketing will not give it to you. The three are not rival paradigms; they are one paradigm with three engineering personalities. When the 2024 competition tally shows all three winning, that is the paradigm winning three ways.

Real world

Teams burn weeks on "XGBoost versus LightGBM" bake-offs that end within a point of each other - which is what session 1's McElfresh finding predicts. The productive question is almost never which engine; it is whether your categories leak, whether your trees are capped, and whether early stopping is on. Tonight is about those questions.

Part 1 · covers LightGBM's speed bets

What LightGBM skips, and why it dares

8 min live

The split search is where boosting spends its time: every node, every feature, every candidate threshold. LightGBM - Ke and colleagues, NeurIPS 2017 - attacks that bill three ways: coarser thresholds (histogram binning), fewer rows (GOSS), fewer features (EFB). Each trick is an approximation with a stated justification, and each justification connects straight back to something you already know.

LiveThe three tricks, each with its receipt5 min▶

Histogram binning (from the docs): bucket each continuous feature into a small number of discrete bins and scan bin boundaries instead of every distinct value. The course's teaching engine already does a crude version of this - its eight candidate thresholds are a tiny histogram - so you have been running the cheap approximation all along, just at toy scale.

GOSS - gradient-based one-side sampling, the paper's first headline idea:

★ Ke et al., NeurIPS 2017 - GOSS "we exclude a significant proportion of data instances with small gradients, and only use the rest to estimate the information gain"

Small gradient means small residual means the model already predicts that row well - session 3's shrinking bars, weaponized. The rows with big gradients are where the remaining signal lives, so the gain estimate barely suffers when the well-learned rows sit out.

EFB - exclusive feature bundling, the second headline:

★ Ke et al., NeurIPS 2017 - EFB "we bundle mutually exclusive features... to reduce the number of features"

Sparse one-hot style columns are rarely nonzero at the same time, so several of them can share one physical column without collisions. Fewer columns, same information, faster scans.

The speedup, quoted against the right baseline. The paper's claim: LightGBM "speeds up the training process of conventional GBDT by up to over 20 times while achieving almost the same accuracy." That is versus conventional pre-sorted GBDT - the exact-scan baseline - NOT versus XGBoost. "LightGBM is 20x faster than XGBoost" is the session-4 misquote pattern all over again: right number, wrong denominator.

SAME BUDGET OF 7 SPLITS · DARK CIRCLES ARE SPLITS, PALE CIRCLES ARE LEAVES Level-wise: spend evenly balanced, depth capped at 3 Leaf-wise: chase max delta loss lopsided, deep where loss lives Docs: leaf-wise converges faster on big data - and on small data it overfits, so cap max_depth. The 300-row lab sample is exactly the risky case.
🔍 Click to zoom - the same 7 splits spent evenly versus spent chasing the deepest loss
LiveLeaf-wise growth - a docs fact, cited as one3 min▶

One famous LightGBM behavior is not in the NeurIPS paper at all - it lives in the documentation, so tonight cites the documentation:

★ LightGBM docs, Features page - leaf-wise growth "LightGBM grows trees leaf-wise (best-first)... will choose the leaf with max delta loss to grow"

Where level-wise growth completes each depth before starting the next, leaf-wise pours its split budget into whichever leaf promises the biggest loss reduction - so the tree gets deep exactly where the loss is concentrated. The docs attach their own warning, and it is not fine print: on small data, leaf-wise overfits, and the recommended defense is to cap max_depth. A best-first search chasing max delta loss on 200 training rows will happily chase the 10 percent label noise to the bottom.

Sourcing discipline, stated once. "It's in the paper" and "it's in the docs" are different citations with different weight - papers are fixed and reviewed, docs move with releases. Tonight's rule, applied throughout: GOSS and EFB and the 20x claim carry the paper's citation; histogram detail and leaf-wise growth carry the docs'. Keep the habit; it costs one clause per claim.

Part 2 · covers CatBoost and the leak

The feature that quietly contains the answer

8 min live

Categorical features do not fit in a threshold split, so practitioners encode them - and the most seductive encoding is the target mean: replace each category with its average churn rate. The trap: computed naively, each row's encoding includes that row's own label. The feature now carries a whisper of the answer, the model learns to listen to the whisper, and the whisper is silent on customers you have not labeled yet.

FIVE MANGO LANE ROWS, ONE CATEGORY COLUMN · CHANNEL A OR B, CHURNED 1 OR 0 Naive target encoding 1 · A · churned (1) 2 · A · stayed (0) 3 · B · churned (1) 4 · B · churned (1) 5 · B · stayed (0) enc 0.50 enc 0.50 enc 0.67 enc 0.67 enc 0.67 Row 3's own label (1) is inside its own 0.67 - the feature whispers the answer back. Ordered target statistics 1 · A · churned (1) 2 · A · stayed (0) 3 · B · churned (1) 4 · B · churned (1) 5 · B · stayed (0) Row 4's encoding uses only rows 1-3, the prefix of a permutation. No row ever sees its own label. The build-along recomputes these five rows by hand: drop each row's own label and row 3's feature falls from 0.67 to 0.50.
🔍 Click to zoom - the leak drawn: a label feeding its own feature versus an encoding that only looks backward
LiveThe paper's claim, quoted precisely4 min▶

Prokhorenkova and colleagues, NeurIPS 2018, name the disease and its reach in one sentence - and the reach is the startling part, so quote it exactly as their claim:

★ Prokhorenkova et al., NeurIPS 2018 - the problem statement "a prediction shift caused by a special kind of target leakage present in all currently existing implementations of gradient boosting algorithms"

"Prediction shift" and "target leakage" are the paper's precise vocabulary, and "all currently existing implementations" is their claim as of 2018 - state it as theirs, not as settled consensus. Their diagnosis covers two doors the label sneaks through: category encodings computed with the row's own label, and the boosting process itself, where every tree is fit on residuals computed by models that already saw those same rows.

The fix has two matching halves. Ordered target statistics: encode each row using only the rows BEFORE it in a random permutation - the prefix - so no row's feature ever contains its own label. Ordered boosting, in the paper's words "a permutation-driven alternative to the classic algorithm": apply the same only-look-backward discipline to the residuals themselves. Same idea, applied to the feature and to the loop.

Real world

This leak does not need CatBoost's problem to bite you. Any pipeline where an analyst adds "churn rate by acquisition channel" as a feature, computed over the full training table, has built the naive encoder by hand. Validation looks great - the leak is in the validation rows too - and production quietly underperforms. If you take one operational habit from tonight: any feature computed FROM the target must be computed as-of, never over the whole table.

Self-studyWhy "prediction shift" and not just "overfitting"2 min▶

The paper's term is chosen carefully. Overfitting is fitting noise; a prediction shift is a systematic bias - the model's predictions on training rows are shifted relative to what the same model produces on genuinely fresh rows, because training rows enjoyed information fresh rows never get. That is why the symptom is a validation-production gap rather than a train-validation gap, and why it survives cross-validation: every fold's encoding was computed the same leaky way. A shifted model can look perfectly regularized and still be wrong in the same direction every time.

Part 3 · covers choosing between the three

One family, three personalities, one honest guide

5 min live

The wrong way to choose is loyalty. The right way is to match each engine's distinguishing bet to the job in front of you - and to remember, from session 1, that light tuning of whichever you pick matters more than the pick.

ONE ROOT, THREE BETS · EVERY BRANCH STILL RUNS THE SAME LOOP The residual loop - session 3 score · residual · fit · scaled add · stop early XGBoost · 2016 bet: priced complexity γ per leaf, λ on weights, second-order gain LightGBM · 2017 bet: speed histograms, GOSS, EFB, leaf-wise growth CatBoost · 2018 bet: categoricals ordered target statistics, ordered boosting 2024 winning solutions: 16 LightGBM, 13 CatBoost, 8 XGBoost - and ensembles mixing several are common. The root wins every time.
🔍 Click to zoom - three engines as one family tree, each branch labeled with its distinguishing bet
LiveThe decision guide, defensible line by line4 min▶
EngineReach for it whenWatch out for
XGBoostYou want the most battle-tested reference implementation, the widest tooling and deployment surface, and a decade of production folkloreNo longer the fastest on big data; categories are your problem to encode safely
LightGBMThe data is big and training time is the bottleneck - the speed bets were built for exactly thisLeaf-wise on small data: the docs' own caveat says cap max_depth
CatBoostMany high-cardinality categoricals - channels, SKUs, regions - and you want leak-safe handling plus strong defaults out of the boxBeing the newest of the three, it has the thinnest folklore; defaults are strong but not magic

Two calibrating facts to staple onto the table. First, revealed preference: the 2024 winning-solution tally - 16 LightGBM, 13 CatBoost, 8 XGBoost, with ensembles mixing several engines common - says practitioners treat all three as winners and pick by fit. Second, the McElfresh reminder from session 1: across 176 datasets, light hyperparameter tuning of a GBDT mattered more than which model was chosen. The gap between engines is real but small; the gap between tuned and untuned is the one you watched cost five points in session 3.

Build-along

Pick the engine for the job

★ 18 min · everyone builds

Five decisions on paper, each one a real decision Mango Lane will face next quarter. The leak computation in step 2 is the heart of tonight - do not skip it; it takes four minutes and inoculates you for a career.

Next quarter's brief lands: two new categorical features. acquisitionChannel, about 12 values, and favoriteCategory, about 200 values. Write which engine you reach for and the one-sentence why. A defensible answer names the 200-value column as the deciding fact - high-cardinality categoricals are CatBoost's home turf - and names what you would do instead if the team insists on staying with the current engine (encode as-of, never over the whole table).

Hand-compute the leak on five rows. Channels A, A, B, B, B with churn 1, 0, 1, 1, 0. Naive encoding: A-mean = (1+0)/2 = 0.50, B-mean = (1+1+0)/3 = 0.67, every row gets its channel's mean. Now recompute each row's encoding EXCLUDING that row's own label: row 1 becomes 0.00, row 2 becomes 1.00, row 3 becomes (1+0)/2 = 0.50, row 4 becomes 0.50, row 5 becomes 1.00. Watch row 3: its feature falls from 0.67 to 0.50 the moment its own label stops contributing. That difference IS the leak - the naive feature was 0.17 of the way to being the answer key.

Leaf-wise or level-wise for the 300-customer lab sample? Decide, and defend it from the docs' own caveat. The defensible call: level-wise or hard-capped leaf-wise - best-first growth chasing max delta loss on 200 training rows will chase the 10 percent label noise, which is precisely the small-data overfit the LightGBM docs warn about.

Audit the course's teaching engine against tonight. Mark which of tonight's tricks it has: histogram binning beyond 8 crude thresholds - no; GOSS - no; EFB - no; leaf-wise growth - no; ordered target statistics - no, it never needed them, the six lab features are all numeric. All of them missing - and that is WHY it fits in 200 readable lines. The teaching engine demonstrates the mechanism; the libraries add the decade.

Predict: would these engines beat the canon 73.0? Write your answer before session 6 measures it. The honest call: marginally at best. The lab sample carries about 10 percent label noise by construction, and no split-search trick recovers labels that are wrong - the binding constraint is the data's noise floor, not the engine. What transfers from tonight is the tuning discipline and the leak hygiene; the magic does not, because there is none.

What to bring to session 6. Your sealed session-4 leaderboard prediction, tonight's engine picks, and your session-1 feature guesses. The finale measures everything: the five-config leaderboard live, SHAP to settle the feature guesses, and the TabPFN challenger given its honest shot.

Homework

Before session 6

30 min
  1. Read the LightGBM Features docs page - the leaf-wise section and its overfitting caveat. Note that the caveat and the feature are in the same paragraph: the library's own authors attach the warning.
  2. Run the leak computation on your own data shape. Take any categorical column you have ever target-encoded (or might), pick five rows, and do the include-versus-exclude computation from step 2. If the two encodings differ visibly, your real pipeline needs the as-of discipline.
  3. Read the CatBoost abstract (arXiv 1706.09516) and find both halves of the fix - the ordered statistics and the ordered boosting. One sentence each, your words.
  4. Write the 20x claim correctly from memory, including its baseline, then check yourself against the paper. If you wrote "faster than XGBoost", tonight's part 1 wants a re-read.
  5. Optional: find one public benchmark comparing the three engines, and check whether it tuned all three equally hard. Most do not - and now you know why that vitiates the comparison.
Check yourself

Three questions

Clear all three and session 5 gets stamped in your passport.

1 · GOSS drops a large share of training rows from the gain estimate. Which rows, and why is that safe?

The paper's words: exclude a significant proportion of instances with small gradients and use the rest to estimate information gain. Small gradient = small residual = already learned - session 3's shrinking bars. The big-gradient rows are where the remaining signal lives, so keeping them preserves the gain estimate. Dropping the LARGE gradients would discard exactly the rows boosting exists to chase.

2 · In the five-row toy (A,A,B,B,B with churn 1,0,1,1,0), row 3's naive encoding is 0.67 but drops to 0.50 when its own label is excluded. What does that difference demonstrate?

The 0.17 gap is row 3's own label leaking into row 3's own feature - CatBoost's "special kind of target leakage" causing a prediction shift. It shrinks with more rows per category but never disappears, and it is worst exactly where target encoding is most tempting: high-cardinality categories with few rows each. Ordered statistics close it by letting each row see only the permutation prefix before it.

3 · The LightGBM paper reports a speedup of "up to over 20 times". Over what baseline?

The paper's claim is versus conventional GBDT with pre-sorted exact split search, "while achieving almost the same accuracy". "20x faster than XGBoost" changes the baseline and becomes a different, unsupported claim - the same denominator discipline as session 4's 17-of-29. Check what a speedup is measured against before repeating it.

Sources covered

What this session teaches, and where it came from

✓Ke et al., LightGBM, NeurIPS 2017GOSS and EFB quoted verbatim; the 20x claim carried with its pre-sorted-GBDT baseline; leaf-wise cited from the docs with the docs' caveat
✓Prokhorenkova et al., CatBoost, NeurIPS 2018Prediction shift and target leakage in the paper's vocabulary; ordered statistics and ordered boosting as the two-part fix
✓ML Contests, State of ML Competitions 2024The revealed-preference tally: 16 LightGBM, 13 CatBoost, 8 XGBoost, mixed ensembles common
◐McElfresh et al., NeurIPS 2023Cited tonight as the tuning-beats-choosing reminder; the full treatment anchors sessions 1 and 6

Every fact on this page, and its verification tier, is recorded in the course's source map.

Session 5 cheat sheet · pin this

GOSSDrop most small-gradient rows, keep the big ones - the already-learned rows barely move the gain estimate.
EFBBundle mutually exclusive sparse features into shared columns. Fewer columns, same information.
Leaf-wise, with its leashBest-first growth chases max delta loss. Docs' own caveat: on small data it overfits - cap max_depth.
20x, right baselineVersus conventional pre-sorted GBDT, at almost the same accuracy. Never "20x faster than XGBoost".
The leakNaive target encoding puts each row's own label in its own feature. Ordered statistics: use only the permutation prefix.
Choosing, honestlyXGBoost: battle-tested reference. LightGBM: biggest data, fastest. CatBoost: high-cardinality categoricals. Tuning matters more.