Unverified Commit aef50f86 authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

[python] fix early_stopping_round = 0 (#3211)

* Update engine.py

* Update sklearn.py
parent 1e2013a3
...@@ -211,7 +211,7 @@ def train(params, train_set, num_boost_round=100, ...@@ -211,7 +211,7 @@ def train(params, train_set, num_boost_round=100,
elif isinstance(verbose_eval, integer_types): elif isinstance(verbose_eval, integer_types):
callbacks.add(callback.print_evaluation(verbose_eval)) 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))) callbacks.add(callback.early_stopping(early_stopping_rounds, first_metric_only, verbose=bool(verbose_eval)))
if learning_rates is not None: if learning_rates is not None:
...@@ -548,7 +548,7 @@ def cv(params, train_set, num_boost_round=100, ...@@ -548,7 +548,7 @@ def cv(params, train_set, num_boost_round=100,
for i, cb in enumerate(callbacks): for i, cb in enumerate(callbacks):
cb.__dict__.setdefault('order', i - len(callbacks)) cb.__dict__.setdefault('order', i - len(callbacks))
callbacks = set(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)) callbacks.add(callback.early_stopping(early_stopping_rounds, first_metric_only, verbose=False))
if verbose_eval is True: if verbose_eval is True:
callbacks.add(callback.print_evaluation(show_stdv=show_stdv)) callbacks.add(callback.print_evaluation(show_stdv=show_stdv))
......
...@@ -602,7 +602,7 @@ class LGBMModel(_LGBMModelBase): ...@@ -602,7 +602,7 @@ class LGBMModel(_LGBMModelBase):
if evals_result: if evals_result:
self._evals_result = 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_iteration = self._Booster.best_iteration
self._best_score = self._Booster.best_score self._best_score = self._Booster.best_score
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment