Sub topic 6
The LightGBM parameters that matter most
This chapter assumes you can train a LightGBM model and read a validation curve. It also assumes you know that a decision tree overfits when it has too many small leaves. LightGBM has more than 100 parameters. A handful of them decide most of the outcome, and this chapter covers those.
Why leaf-wise growth changes which parameters matter
LightGBM grows trees leaf-wise. At each step it splits the single leaf with the largest loss reduction, wherever that leaf is. Trees therefore become lopsided, and depth is a poor measure of how complex a tree is. The number of leaves and the amount of data in each leaf are better measures. Most of the important parameters limit one of those two things.
Parameters that control tree complexity
num_leaves
num_leaves is the maximum number of leaves in one tree. The default is 31. It is the main complexity control. Doubling it lets each tree capture more feature interactions, and it also makes the model fit noise more easily.
A depth-limited tree has at most 2^depth leaves, so a depth of 6 corresponds to 64 leaves. Keep num_leaves well below 2^max_depth if you set both. Otherwise the depth limit does nothing.
min_data_in_leaf
min_data_in_leaf is the minimum number of training rows in a leaf. The default is 20. A split is rejected if either child would have fewer rows. Raising it is the most direct way to stop leaf-wise growth from carving out tiny leaves that memorize a few rows. On a dataset with millions of rows, 20 is very small, and values in the hundreds are common.
max_depth
max_depth is -1 by default, which means no limit. A limit such as 6 to 10 gives a hard cap on how deep a single branch can go. It is a useful safety net on small datasets.
min_gain_to_split and min_sum_hessian_in_leaf
min_gain_to_split is the minimum loss reduction required to make a split. The default is 0. min_sum_hessian_in_leaf is the minimum sum of second derivatives in a leaf. The default is 0.001. This second parameter matters more than it looks for losses such as log loss, where the second derivative shrinks for confident predictions. Both are secondary knobs. Reach for them after the parameters above.
Parameters that control the learning schedule
learning_rate and the number of rounds
learning_rate scales how much each new tree contributes. The default is 0.1. Lower values need more trees but usually generalize better. A common workflow is to set a fixed rate such as 0.05, set a large round limit, and let early stopping choose the number of trees. If you halve the rate, expect the best iteration to roughly double.
The number of rounds is n_estimators in the scikit-learn API and num_boost_round in lgb.train. Treat it as an upper bound, not a tuned value.
Parameters that add randomness
feature_fraction
feature_fraction is the fraction of features sampled for each tree. The default is 1.0. Values like 0.7 to 0.9 make trees less alike and reduce overfitting when many features are correlated. It also speeds up training.
bagging_fraction and bagging_freq
bagging_fraction is the fraction of rows sampled for a tree. bagging_freq is how often to resample, in iterations. Row sampling happens only if bagging_freq is greater than 0.
Parameters that regularize leaf values
lambda_l1 and lambda_l2 penalize large leaf outputs. Both default to 0. L2 shrinks every leaf value smoothly. L1 pushes small leaf values to exactly zero. They help most when num_leaves is large or the target is noisy. Try values like 1 and 10 and keep them only if validation improves.
Parameters that trade accuracy for speed
max_bin is the number of histogram bins per feature. The default is 255. Fewer bins train faster and use less memory, but split points become coarser. Raising it above 255 rarely helps.
Name aliases between the two APIs
The native API and the scikit-learn API use different names for the same parameters. Mixing them in one call can raise warnings or silently pick one value.
| Native name | scikit-learn name | Default |
|---|---|---|
| num_leaves | num_leaves | 31 |
| min_data_in_leaf | min_child_samples | 20 |
| feature_fraction | colsample_bytree | 1.0 |
| bagging_fraction | subsample | 1.0 |
| bagging_freq | subsample_freq | 0 |
| lambda_l1 | reg_alpha | 0 |
| lambda_l2 | reg_lambda | 0 |
| min_gain_to_split | min_split_gain | 0 |
A practical tuning order
Tune in order of impact, and change one group at a time. Each stage uses early stopping on the same validation set.
Comparing settings with the same validation set
The code below trains four models that differ only in num_leaves and min_child_samples. It reports the validation RMSE and the number of trees that early stopping kept.
import lightgbm as lgb
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing(return_X_y=True, as_frame=True)
X_train, X_valid, y_train, y_valid = train_test_split(
X, y, test_size=0.2, random_state=0
)
settings = [
{"num_leaves": 15, "min_child_samples": 20},
{"num_leaves": 31, "min_child_samples": 20},
{"num_leaves": 127, "min_child_samples": 20},
{"num_leaves": 127, "min_child_samples": 100},
]
for s in settings:
model = lgb.LGBMRegressor(
n_estimators=2000,
learning_rate=0.05,
colsample_bytree=0.8,
subsample=0.8,
subsample_freq=1,
verbose=-1,
**s,
)
model.fit(
X_train,
y_train,
eval_set=[(X_valid, y_valid)],
eval_metric="rmse",
callbacks=[lgb.early_stopping(stopping_rounds=50, verbose=False)],
)
rmse = model.best_score_["valid_0"]["rmse"]
print(s, "best_iteration:", model.best_iteration_, "rmse:", round(rmse, 4))Look at two things in the output. First, larger num_leaves usually reaches a lower RMSE in fewer trees, because each tree does more work. Second, raising min_child_samples on the large trees tests whether the extra leaves help or only fit noise. Your exact numbers depend on the library version.
Common errors
- Tuning on the test set. Choose parameters on a validation set or with cross-validation. Report the final score on data that played no part in the choice.
- Tuning
n_estimatorsdirectly. With early stopping, the number of rounds is an output. Set it high and readbest_iteration_. - Raising
num_leaveswithout raisingmin_data_in_leaf. More leaves on the same data means fewer rows per leaf. The two parameters should move together. - Copying parameters from a large dataset to a small one. A value of
min_data_in_leaf=200on 1,000 rows prevents almost all splits, and the model underfits. - Reusing the validation set for early stopping and for the final score. Early stopping picks the best round on that set, so its score is slightly optimistic.
Exercise
A model trained with numleaves=255, mindatainleaf=20, and baggingfraction=0.7 (baggingfreq left at its default) shows a training AUC of 0.99 and a validation AUC of 0.81. Name two parameter changes you would try, and say what the bagging setting currently does.
Show answer
Lower numleaves (for example to 31 or 63) and raise mindatainleaf (for example to 100 or more), because the large gap between training and validation AUC shows overfitting from too many small leaves. The bagging setting currently does nothing, because baggingfreq is 0 and row sampling only happens when baggingfreq is greater than 0. Setting baggingfreq=1 would enable it and add more regularization. Adding featurefraction below 1.0 or lambda_l2 would also be reasonable.