From 707dec9f0b7fc2b5c4a2e04db348550bb18307aa Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 22:48:21 +0300 Subject: [PATCH 1/8] Update __init__.py --- python-package/lightgbm/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-package/lightgbm/__init__.py b/python-package/lightgbm/__init__.py index 8af6253b46a2..2c4f07dd6e3c 100644 --- a/python-package/lightgbm/__init__.py +++ b/python-package/lightgbm/__init__.py @@ -6,7 +6,7 @@ from pathlib import Path from .basic import Booster, Dataset, Sequence, register_logger -from .callback import early_stopping, print_evaluation, record_evaluation, reset_parameter +from .callback import early_stopping, log_evaluation, print_evaluation, record_evaluation, reset_parameter from .engine import CVBooster, cv, train try: @@ -32,5 +32,5 @@ 'train', 'cv', 'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker', 'DaskLGBMRegressor', 'DaskLGBMClassifier', 'DaskLGBMRanker', - 'print_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping', + 'log_evaluation', 'print_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping', 'plot_importance', 'plot_split_value_histogram', 'plot_metric', 'plot_tree', 'create_tree_digraph'] From 0ce506e338f0bc43f3fec05c6deeec93d70108d4 Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 22:48:55 +0300 Subject: [PATCH 2/8] Update Python-API.rst --- docs/Python-API.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Python-API.rst b/docs/Python-API.rst index f57125c46a5a..3e0dab74fbf8 100644 --- a/docs/Python-API.rst +++ b/docs/Python-API.rst @@ -53,7 +53,7 @@ Callbacks :toctree: pythonapi/ early_stopping - print_evaluation + log_evaluation record_evaluation reset_parameter From 63db9ba7ebdf1a0c33f0fd0c621627b489bdff12 Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 22:52:22 +0300 Subject: [PATCH 3/8] Update engine.py --- python-package/lightgbm/engine.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python-package/lightgbm/engine.py b/python-package/lightgbm/engine.py index 2c1a3fc28c95..4a7b5f50ca65 100644 --- a/python-package/lightgbm/engine.py +++ b/python-package/lightgbm/engine.py @@ -238,16 +238,16 @@ def train( # Most of legacy advanced options becomes callbacks if verbose_eval != "warn": _log_warning("'verbose_eval' argument is deprecated and will be removed in a future release of LightGBM. " - "Pass 'print_evaluation()' callback via 'callbacks' argument instead.") + "Pass 'log_evaluation()' callback via 'callbacks' argument instead.") else: - if callbacks: # assume user has already specified print_evaluation callback + if callbacks: # assume user has already specified log_evaluation callback verbose_eval = False else: verbose_eval = True if verbose_eval is True: - callbacks.add(callback.print_evaluation()) + callbacks.add(callback.log_evaluation()) elif isinstance(verbose_eval, int): - callbacks.add(callback.print_evaluation(verbose_eval)) + callbacks.add(callback.log_evaluation(verbose_eval)) 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))) @@ -619,11 +619,11 @@ def cv(params, train_set, num_boost_round=100, callbacks.add(callback.early_stopping(early_stopping_rounds, first_metric_only, verbose=False)) if verbose_eval is not None: _log_warning("'verbose_eval' argument is deprecated and will be removed in a future release of LightGBM. " - "Pass 'print_evaluation()' callback via 'callbacks' argument instead.") + "Pass 'log_evaluation()' callback via 'callbacks' argument instead.") if verbose_eval is True: - callbacks.add(callback.print_evaluation(show_stdv=show_stdv)) + callbacks.add(callback.log_evaluation(show_stdv=show_stdv)) elif isinstance(verbose_eval, int): - callbacks.add(callback.print_evaluation(verbose_eval, show_stdv=show_stdv)) + callbacks.add(callback.log_evaluation(verbose_eval, show_stdv=show_stdv)) callbacks_before_iter = {cb for cb in callbacks if getattr(cb, 'before_iteration', False)} callbacks_after_iter = callbacks - callbacks_before_iter From 2e521d8177325685ea6bf8ebfaa878248bd496cf Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 22:52:58 +0300 Subject: [PATCH 4/8] Update test_utilities.py --- tests/python_package_test/test_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python_package_test/test_utilities.py b/tests/python_package_test/test_utilities.py index 2fdacf8e8869..02da77fc56e6 100644 --- a/tests/python_package_test/test_utilities.py +++ b/tests/python_package_test/test_utilities.py @@ -33,7 +33,7 @@ def dummy_metric(_, __): eval_records = {} callbacks = [ lgb.record_evaluation(eval_records), - lgb.print_evaluation(2), + lgb.log_evaluation(2), lgb.early_stopping(4) ] lgb.train({'objective': 'binary', 'metric': ['auc', 'binary_error']}, From dac2f77fb6a1b07ec80ed8f64bd7c51ac1e3196a Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 22:58:28 +0300 Subject: [PATCH 5/8] Update sklearn.py --- python-package/lightgbm/sklearn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python-package/lightgbm/sklearn.py b/python-package/lightgbm/sklearn.py index 9aeac2403b1d..a200071d5611 100644 --- a/python-package/lightgbm/sklearn.py +++ b/python-package/lightgbm/sklearn.py @@ -7,7 +7,7 @@ import numpy as np from .basic import Dataset, LightGBMError, _choose_param_value, _ConfigAliases, _log_warning -from .callback import print_evaluation, record_evaluation +from .callback import log_evaluation, record_evaluation from .compat import (SKLEARN_INSTALLED, LGBMNotFittedError, _LGBMAssertAllFinite, _LGBMCheckArray, _LGBMCheckClassificationTargets, _LGBMCheckSampleWeight, _LGBMCheckXY, _LGBMClassifierBase, _LGBMComputeSampleWeight, _LGBMLabelEncoder, _LGBMModelBase, _LGBMRegressorBase, dt_DataTable, @@ -731,13 +731,13 @@ def _get_meta_data(collection, name, i): if verbose != 'warn': _log_warning("'verbose' argument is deprecated and will be removed in a future release of LightGBM. " - "Pass 'print_evaluation()' callback via 'callbacks' argument instead.") + "Pass 'log_evaluation()' callback via 'callbacks' argument instead.") else: - if callbacks: # assume user has already specified print_evaluation callback + if callbacks: # assume user has already specified log_evaluation callback verbose = False else: verbose = True - callbacks.append(print_evaluation(int(verbose))) + callbacks.append(log_evaluation(int(verbose))) evals_result = {} callbacks.append(record_evaluation(evals_result)) From 09f2c0cd19d982f27c1007bd56fffeff224b952f Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 23:03:07 +0300 Subject: [PATCH 6/8] Update callback.py --- python-package/lightgbm/callback.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python-package/lightgbm/callback.py b/python-package/lightgbm/callback.py index fb16deed409c..11614b43e696 100644 --- a/python-package/lightgbm/callback.py +++ b/python-package/lightgbm/callback.py @@ -48,8 +48,13 @@ def _format_eval_result(value: list, show_stdv: bool = True) -> str: else: raise ValueError("Wrong metric value") - def print_evaluation(period: int = 1, show_stdv: bool = True) -> Callable: + _log_warning("'print_evaluation()' callback is deprecated and will be removed in a future release of LightGBM. " + "Use 'log_evaluation()' callback instead.") + return log_evaluation(period=period, show_stdv=show_stdv) + + +def log_evaluation(period: int = 1, show_stdv: bool = True) -> Callable: """Create a callback that logs the evaluation results. By default, standard output resource is used. From 801452fc4919739bf2a45b078e5c923d2d3b0d8f Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 23:08:14 +0300 Subject: [PATCH 7/8] Update callback.py --- python-package/lightgbm/callback.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python-package/lightgbm/callback.py b/python-package/lightgbm/callback.py index 11614b43e696..4a527b49401f 100644 --- a/python-package/lightgbm/callback.py +++ b/python-package/lightgbm/callback.py @@ -48,6 +48,7 @@ def _format_eval_result(value: list, show_stdv: bool = True) -> str: else: raise ValueError("Wrong metric value") + def print_evaluation(period: int = 1, show_stdv: bool = True) -> Callable: _log_warning("'print_evaluation()' callback is deprecated and will be removed in a future release of LightGBM. " "Use 'log_evaluation()' callback instead.") From 10f958e5419ecc0a8614254f1c94058db8f8f4ea Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Sun, 12 Sep 2021 23:14:39 +0300 Subject: [PATCH 8/8] Update callback.py --- python-package/lightgbm/callback.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python-package/lightgbm/callback.py b/python-package/lightgbm/callback.py index 4a527b49401f..f7e574ece020 100644 --- a/python-package/lightgbm/callback.py +++ b/python-package/lightgbm/callback.py @@ -50,6 +50,10 @@ def _format_eval_result(value: list, show_stdv: bool = True) -> str: def print_evaluation(period: int = 1, show_stdv: bool = True) -> Callable: + """Create a callback that logs the evaluation results. + + Deprecated, use ``log_evaluation()`` instead. + """ _log_warning("'print_evaluation()' callback is deprecated and will be removed in a future release of LightGBM. " "Use 'log_evaluation()' callback instead.") return log_evaluation(period=period, show_stdv=show_stdv)