LightGBM: early_stopping_rounds is ignored in python interface when specified via parameters dict

The parameter early_stopping_rounds is ignored when it is set via the parameters dictionary but it works fine when it is explicitly specified in the call lgb.train. I think this should be fixed or the documentation needs a note that this parameter is ignored in the python interface (like the note for num_iterations in http://lightgbm.readthedocs.io/en/latest/Parameters.html)

Here is a code example:

import lightgbm as lgb
import numpy as np
import pandas as pd

n=1000
X = np.random.randint(1000, size=(n,2))
y = X[:,0]+X[:,1] + np.random.normal(size=n)

Xtrain, ytrain = X[:int(.5*n),:], y[:int(.5*n)]
Xval, yval = X[int(.5*n):,:], y[int(.5*n):]

ds_train = lgb.Dataset(Xtrain, ytrain)
ds_val = lgb.Dataset(Xval, yval)

params = {'objective':'regression_l2',  'metric':'rmse', 'learning_rate':.01,'early_stopping_rounds':10}
gbm = lgb.train(params, ds_train, valid_sets=[ds_val, ds_train], categorical_feature=[1],verbose_eval=20,num_boost_round=1000)
print("=============================================")
gbm = lgb.train(params, ds_train, valid_sets=[ds_val, ds_train], categorical_feature=[1],verbose_eval=20,num_boost_round=1000,early_stopping_rounds=10)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (10 by maintainers)

Most upvoted comments

@wxchan besides updating docs, I think we also can add some warnings in python/R package if user pass these parameters into dict. Another solution is reading these parameters from dict.

BTW, there are some other parameters also have this problem, e.g. categorical_ feature

@guolinke already working on this.

ok, we will add a note into doc.