How to plot the learning curves in lightgbm and Python?
In the scikit-learn API, the learning curves are available via attribute lightgbm.LGBMModel.evals_result_
. They will include metrics computed with datasets specified in the argument eval_set
of method fit
(so you would normally want to specify there both the training and the validation sets). There is also built-in plotting function, lightgbm.plot_metric
, which accepts model.evals_result_
or model
directly.
Here is a complete minimal example:
import lightgbm as lgbimport sklearn.datasets, sklearn.model_selectionX, y = sklearn.datasets.load_boston(return_X_y=True)X_train, X_val, y_train, y_val = sklearn.model_selection.train_test_split(X, y, random_state=7054)model = lgb.LGBMRegressor(objective='mse', seed=8798, num_threads=1)model.fit(X_train, y_train, eval_set=[(X_val, y_val), (X_train, y_train)], verbose=10)lgb.plot_metric(model)
Here is the resulting plot: