抑制 optunas cv_agg 的 binary_logloss 输出

Supressing optunas cv_agg's binary_logloss output

如果我使用 LightGBMTunerCV 调整模型,我总是会得到 cv_agg 的 binary_logloss 的巨大结果。如果我使用更大的数据集执行此操作,这个(不必要的)io 会降低优化过程的性能。

代码如下:

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
import optuna.integration.lightgbm as lgb
import optuna

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
warnings.simplefilter(action='ignore', category=UserWarning)
breast_cancer = load_breast_cancer()

X_train, X_test, Y_train, Y_test = train_test_split(breast_cancer.data, breast_cancer.target)

train_dataset = lgb.Dataset(X_train, Y_train, feature_name=breast_cancer.feature_names.tolist())
test_dataset = lgb.Dataset(X_test, Y_test, feature_name=breast_cancer.feature_names.tolist())
callbacks = [lgb.log_evaluation(period=0)]
tuner = lgb.LightGBMTunerCV({"objective": "binary", 'verbose': -1},
       train_set=test_dataset, num_boost_round=10,
       nfold=5, stratified=True, shuffle=True)


tuner.run()

并且输出:

feature_fraction, val_score: 0.327411:  43%|###################2      | 3/7 [00:00<00:00, 13.84it/s]
[1] cv_agg's binary_logloss: 0.609496 + 0.009315
[2] cv_agg's binary_logloss: 0.554522 + 0.00607596
[3] cv_agg's binary_logloss: 0.512217 + 0.0132959
[4] cv_agg's binary_logloss: 0.479142 + 0.0168108
[5] cv_agg's binary_logloss: 0.440044 + 0.0166129
[6] cv_agg's binary_logloss: 0.40653 + 0.0200005
[7] cv_agg's binary_logloss: 0.382273 + 0.0242429
[8] cv_agg's binary_logloss: 0.363559 + 0.03312

有什么办法可以去掉这个输出吗?

感谢您的帮助!

您可以在 LightGBMTunerCV() 中传递值为 None 的 verbose_eval 参数。

示例:

tuner = lgb.LightGBMTunerCV({"objective": "binary", 'verbose': -1},
       train_set=test_dataset, num_boost_round=10,
       nfold=5, stratified=True, shuffle=True, verbose_eval=None)