XGBoost, LightGBM, histogram boosting and CatBoost
Four implementations of one idea. Learn how they differ in tree growth and in Python-to-R agreement, and why default-to-default gaps are rarely worth a debate.
What runs in CodeSplash
- XGBoost Verified in Python and R
- LightGBM Verified in Python and R
- Histogram gradient boosting Verified in Python and R
- CatBoost Preview
You will be able to
- Tell level-wise from leaf-wise growth, and say what each risks
- Choose a library from speed, agreement between engines and data shape
- Read small gaps between libraries as noise until shown otherwise
Read first
One idea, four engines
Read| Learner | Grows trees | Agreement between Python and R |
|---|---|---|
| XGBoost | Level by level, on histograms | Same core: floating-point precision |
| LightGBM | Leaf by leaf, on histograms | Same core: floating-point precision |
| Histogram gradient boosting | Leaf by leaf, on histograms | scikit-learn in Python, LightGBM in R: same kind of model, statistical agreement |
| CatBoost | Symmetric trees, ordered boosting | Same core, preview in this build |
All of them handle missing values natively, and none needs scaling.
Level by level, or leaf by leaf?
ReadLevel-wise growth splits every node at each depth, so trees stay balanced.
Leaf-wise growth always splits the single leaf that helps most. It finds more with fewer leaves, and on small data it can dig a deep, narrow branch around noise. That's why Leaves per tree and Minimum rows per leaf matter so much on LightGBM.
Histogram binning buckets each feature first, which makes them all far faster on large tables.
Who wins?
PredictPredict first
Compare three libraries on Pima (AUC, higher is better), ozone (RMSE, lower is better) and penguins (log loss, lower is better). Settings are light and differ a little. What pattern do you expect?
Reveal
Small differences that flip. AUC: 0.843, 0.829, 0.822, and plain logistic gets 0.857. RMSE: 18.2, 18.6, 18.4. Tuning a library usually matters more than picking it.
Choosing
Read- Large table, need speed: LightGBM or histogram boosting.
- Must match digit for digit between Python and R: XGBoost or LightGBM.
- Need exact contributions: XGBoost or LightGBM, both with TreeSHAP.
- Many categories, little tuning time: CatBoost, when available.
CatBoost is a preview learner in this build: its R package isn't on CRAN, so Python-to-R agreement hasn't been checked yet.
See how small a gap is
ExploreSet Noise SD high and Training rows n low. Change Tree depth and Learning rate (boosting). Then change only Data. How much do the scores move with the draw alone, compared with what your settings did?
DExplorable · Bagging and boosting
How do many weak trees combine into a strong model?
With up to 200 trees available, at how many trees will error on new data be lowest?
Method
Commit your prediction above to see the result
Make your prediction to see the result.
Before you switch libraries for a small lead, look at that band.
Check your understanding
CheckpointCheck yourself
What's the main overfitting risk of leaf-wise growth?
Show the answer
Answer: a
Choosing the leaf with the largest gain is efficient, but it has no built-in balance. Minimum rows per leaf is the usual guard on small data.
Check yourself
Why can Histogram gradient boosting differ between Python and R more than LightGBM does?
Show the answer
Answer: b
Same family, different code. Pick LightGBM or XGBoost when you need digit-level agreement.
Check yourself
LightGBM beats XGBoost by a little on your leaderboard, and the chip reads ≈ best. What should you do?
Show the answer
Answer: a
A tie means the data can't separate them. Adding more candidates also adds more selection bias.
Check yourself
What does histogram binning buy?
Show the answer
Answer: b
A split search scans bins, not sorted rows. The small loss of precision rarely matters.
Compare them
In the appIn the Learners step, select XGBoost, LightGBM and Histogram gradient boosting, then press Train 3 models. On the Leaderboard, look at the chips, then tick the rows and press Compare 3. Verify in R (or Python) fills in Py ≡ R: expect an exact match for the first two.
import lightgbm as lgb
import pandas as pd
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.model_selection import StratifiedKFold, cross_val_score
from xgboost import XGBClassifier
df = pd.read_csv("pima.csv")
X, y = df.drop(columns="diabetic"), df["diabetic"]
cv = StratifiedKFold(5, shuffle=True, random_state=1)
models = {"xgboost": XGBClassifier(n_estimators=40, max_depth=3),
"lightgbm": lgb.LGBMClassifier(n_estimators=40, num_leaves=8, verbose=-1),
"hist_gb": HistGradientBoostingClassifier(max_iter=60, max_leaf_nodes=8)}
for name, m in models.items():
print(name, cross_val_score(m, X, y, cv=cv, scoring="roc_auc").mean().round(3))library(lightgbm)
df <- rbind(MASS::Pima.tr, MASS::Pima.te)
X <- as.matrix(df[, setdiff(names(df), "type")])
y <- as.numeric(df$type == "Yes")
set.seed(1)
fold <- sample(rep(1:5, length.out = nrow(X)))
auc <- sapply(1:5, function(k) {
fit <- lgb.train(list(objective = "binary", num_leaves = 8, verbose = -1),
lgb.Dataset(X[fold != k, ], label = y[fold != k]), nrounds = 40)
as.numeric(pROC::auc(y[fold == k], predict(fit, X[fold == k, ]), quiet = TRUE))
})
round(mean(auc), 3)Recap
Recap- All four are gradient boosting. They differ in how trees grow and how fast they fit.
- Default-to-default gaps are usually smaller than the noise, and they flip across datasets.
- Choose on speed, engine agreement and explainability. Then tune one well.
Concepts in this lesson