LightGBM Cheat Sheet
LightGBM reference covering the scikit-learn and native Dataset APIs, leaf-wise tree growth, and the hyperparameters that control speed and overfitting.
2 PagesIntermediateApr 15, 2026
Scikit-learn API
Familiar fit/predict interface.
python
import lightgbm as lgbfrom lightgbm import LGBMClassifiermodel = LGBMClassifier( n_estimators=500, num_leaves=31, learning_rate=0.05, subsample=0.8, colsample_bytree=0.8, random_state=42,)model.fit( X_train, y_train, eval_set=[(X_val, y_val)], callbacks=[lgb.early_stopping(stopping_rounds=30)],)preds = model.predict(X_test)
Native Dataset API
Lower-level API with more control.
python
train_data = lgb.Dataset(X_train, label=y_train)val_data = lgb.Dataset(X_val, label=y_val, reference=train_data)params = { "objective": "binary", "metric": "binary_logloss", "num_leaves": 31, "learning_rate": 0.05,}booster = lgb.train( params, train_data, num_boost_round=500, valid_sets=[val_data], callbacks=[lgb.early_stopping(30), lgb.log_evaluation(50)],)
Key Hyperparameters
Parameters that matter most for tuning.
- num_leaves- main complexity control for leaf-wise tree growth
- max_depth- limits tree depth (default -1 = unlimited)
- learning_rate- shrinkage applied to each new tree
- feature_fraction- fraction of features sampled per iteration
- bagging_fraction- fraction of rows sampled per iteration
- min_data_in_leaf- minimum samples per leaf, prevents overfitting
- categorical_feature- column names/indices for native categorical handling
Cross-Validation
Built-in CV helper for the native API.
python
cv_results = lgb.cv( params, train_data, num_boost_round=500, nfold=5, stratified=True, callbacks=[lgb.early_stopping(30)],)print(min(cv_results["valid binary_logloss-mean"]))
Pro Tip
LightGBM grows trees leaf-wise (best-first) rather than level-wise, which trains faster and often reaches higher accuracy — but it's more prone to overfitting on small datasets, so tune num_leaves and min_data_in_leaf together.
Was this cheat sheet helpful?
Explore Topics
#LightGBM#LightGBMCheatSheet#DataScience#Intermediate#ScikitLearnAPI#NativeDatasetAPI#KeyHyperparameters#CrossValidation#DataStructures#MachineLearning#APIs#CheatSheet#SkillVeris