Skip to content

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.

Applied ~10 min8 steps

What runs in CodeSplash

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

01

One idea, four engines

Read
LearnerGrows treesAgreement between Python and R
XGBoostLevel by level, on histogramsSame core: floating-point precision
LightGBMLeaf by leaf, on histogramsSame core: floating-point precision
Histogram gradient boostingLeaf by leaf, on histogramsscikit-learn in Python, LightGBM in R: same kind of model, statistical agreement
CatBoostSymmetric trees, ordered boostingSame core, preview in this build

All of them handle missing values natively, and none needs scaling.

02

Level by level, or leaf by leaf?

Read

Level-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.

03

Who wins?

Predict

Predict 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?

XGBoost wins on all of themLightGBM wins on all of themDifferences are small and flip across datasets
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.

04

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.

05

See how small a gap is

Explore

Set 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?

101
How sure?

Method

25
0.20
2
0.35
80
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Before you switch libraries for a small lead, look at that band.

06

Check your understanding

Checkpoint

Check 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.

07

Compare them

In the app

In 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.

Python
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))
R
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)
08

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