Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python][sklearn] do not replace empty dict with None for evals_result_ #4884

Merged
merged 3 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions python-package/lightgbm/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,7 @@ def _get_meta_data(collection, name, i):
callbacks=callbacks
)

if evals_result:
self._evals_result = evals_result
else: # reset after previous call to fit()
self._evals_result = None

self._evals_result = evals_result
self._best_iteration = self._Booster.best_iteration
self._best_score = self._Booster.best_score

Expand Down Expand Up @@ -910,7 +906,7 @@ def booster_(self):

@property
def evals_result_(self):
""":obj:`dict` or :obj:`None`: The evaluation results if validation sets have been specified."""
""":obj:`dict`: The evaluation results if validation sets have been specified."""
if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No results found. Need to call fit with eval_set beforehand.')
return self._evals_result
Expand Down
6 changes: 3 additions & 3 deletions tests/python_package_test/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def test_metrics():

# no metric
gbm = lgb.LGBMRegressor(metric='None', **params).fit(**params_fit)
assert gbm.evals_result_ is None
assert gbm.evals_result_ == {}

# non-default metric in eval_metric
gbm = lgb.LGBMRegressor(**params).fit(eval_metric='mape', **params_fit)
Expand Down Expand Up @@ -833,7 +833,7 @@ def test_metrics():
# no metric
gbm = lgb.LGBMRegressor(objective='regression_l1', metric='None',
**params).fit(**params_fit)
assert gbm.evals_result_ is None
assert gbm.evals_result_ == {}

# non-default metric in eval_metric for non-default objective
gbm = lgb.LGBMRegressor(objective='regression_l1',
Expand Down Expand Up @@ -878,7 +878,7 @@ def test_metrics():
# no metric
gbm = lgb.LGBMRegressor(objective=custom_dummy_obj, metric='None',
**params).fit(**params_fit)
assert gbm.evals_result_ is None
assert gbm.evals_result_ == {}

# default regression metric with non-default metric in eval_metric for custom objective
gbm = lgb.LGBMRegressor(objective=custom_dummy_obj,
Expand Down