Sub topic 6
The LightGBM parameters that matter most
This chapter assumes you know how gradient boosted trees work, and that LightGBM bins features into histograms and grows trees leaf-wise. It also assumes you can read RMSE, log loss and AUC. Here you will learn which parameters control model complexity and which ones you can leave alone at first.
Why a few parameters dominate
LightGBM has more than 100 parameters. Most tuning effort goes into a small group. Because trees grow leaf-wise, the number of leaves sets complexity directly. Depth, leaf size and regularization then limit how far the trees can specialize.
Parameters that control tree complexity
| Parameter | Default | What it does | Direction when overfitting |
|---|---|---|---|
| `num_leaves` | 31 | Maximum leaves per tree. The main complexity control. | Lower it |
| `min_data_in_leaf` (`min_child_samples` in the sklearn API) | 20 | Minimum rows in a leaf. | Raise it |
| `max_depth` | -1 (no limit) | Caps tree depth as a safety limit. | Set it, for example 6 to 12 |
| `lambda_l2` (`reg_lambda`) | 0 | L2 penalty on leaf values. | Raise it |
A tree with depth d can have at most 2^d leaves. Keep num_leaves well below 2^max_depth. If max_depth=5, setting num_leaves=127 has no effect, because a depth-5 tree has at most 32 leaves.
Parameters that control the learning schedule
learning_rate(default 0.1) scales each tree's contribution. Smaller values need more trees but usually generalize better.num_boost_round(n_estimatorsin the sklearn API) sets the maximum number of trees. Set it high and let early stopping choose the real number.
A practical pattern: pick learning_rate between 0.02 and 0.1, set a large tree limit, and stop on the validation metric. Lowering the rate later gives a small gain at the cost of training time.
Parameters that add randomness
feature_fraction(colsample_bytree) uses a random share of columns for each tree.bagging_fraction(subsample) uses a random share of rows. It only works whenbagging_freqis greater than 0.
Values from 0.7 to 0.9 often reduce variance and speed up training.
A parameter set in practice
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
)
params = {
"objective": "regression",
"metric": "rmse",
"learning_rate": 0.05,
"num_leaves": 31,
"min_data_in_leaf": 50,
"max_depth": 8,
"lambda_l2": 1.0,
"feature_fraction": 0.8,
"bagging_fraction": 0.8,
"bagging_freq": 1,
"verbose": -1,
}
train_set = lgb.Dataset(X_train, label=y_train)
valid_set = lgb.Dataset(X_valid, label=y_valid, reference=train_set)
booster = lgb.train(
params,
train_set,
num_boost_round=2000,
valid_sets=[valid_set],
callbacks=[lgb.early_stopping(50)],
)
print(booster.best_iteration, booster.best_score["valid_0"]["rmse"])Common errors
- Tuning
num_leavesupward while leavingmin_data_in_leafat its default on a small dataset. - Using the sklearn alias in a native
paramsdict, or the reverse. Aliases are mostly accepted, but mixing both names for one setting gives a warning and an unclear winner. - Comparing learning rates without early stopping, so each model gets a different, arbitrary number of trees.
Exercise
A model has max_depth=4 and num_leaves=200. Training RMSE is much lower than validation RMSE. Which parameter would you change first, and why will changing num_leaves alone not help much?
Show answer
A depth-4 tree has at most 2^4 = 16 leaves, so num_leaves=200 is never reached and lowering it to any value above 16 changes nothing. To reduce overfitting, raise min_data_in_leaf, raise lambda_l2, or lower max_depth or num_leaves below 16.