[python] fix early_stopping_round = 0 (#3211)

* Update engine.py

* Update sklearn.py
This commit is contained in:
Guolin Ke 2020-07-08 00:48:08 +08:00 коммит произвёл GitHub
Родитель 1e2013a306
Коммит aef50f8614
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -211,7 +211,7 @@ def train(params, train_set, num_boost_round=100,
elif isinstance(verbose_eval, integer_types):
callbacks.add(callback.print_evaluation(verbose_eval))
if early_stopping_rounds is not None:
if early_stopping_rounds is not None and early_stopping_rounds > 0:
callbacks.add(callback.early_stopping(early_stopping_rounds, first_metric_only, verbose=bool(verbose_eval)))
if learning_rates is not None:
@ -548,7 +548,7 @@ def cv(params, train_set, num_boost_round=100,
for i, cb in enumerate(callbacks):
cb.__dict__.setdefault('order', i - len(callbacks))
callbacks = set(callbacks)
if early_stopping_rounds is not None:
if early_stopping_rounds is not None and early_stopping_rounds > 0:
callbacks.add(callback.early_stopping(early_stopping_rounds, first_metric_only, verbose=False))
if verbose_eval is True:
callbacks.add(callback.print_evaluation(show_stdv=show_stdv))

Просмотреть файл

@ -602,7 +602,7 @@ class LGBMModel(_LGBMModelBase):
if evals_result:
self._evals_result = evals_result
if early_stopping_rounds is not None:
if early_stopping_rounds is not None and early_stopping_rounds > 0:
self._best_iteration = self._Booster.best_iteration
self._best_score = self._Booster.best_score