我想知道如何停止 lightgbm 日志记录。 我应该使用什么样的设置来停止日志? 另外,有没有办法在lightgbm日志停止的情况下只输出自己的日志?
遵循以下几点。
更新了 2024 年的答案 (
lightgbm>=4.3.0
),描述了如何抑制 lightgbm
(LightGBM 的 Python 包)的所有日志输出。
如果使用来自
lightgbm.sklearn
估计器的估计器:
verbosity=-1
传递给估计器构造函数如果使用
lightgbm.train()
或 lightgbm.cv()
:
"verbosity": -1
关键字参数传递
params
如果两个接口在关键字参数和通过其他方式传递的配置之间遇到冲突,它们都会发出
UserWarning
(对于 scikit-learn 为 **kwargs
,对于 params
/ cv()
为 train()
字典。也可以抑制这些:
warnings.filterwarnings("ignore", category=UserWarning)
使用 Python 3.11、
lightgbm==4.3.0
和 scikit==1.4.1
,对所有示例进行以下导入和设置:
import lightgbm as lgb
import warnings
from sklearn.datasets import make_regression
# create datasets
X, y = make_regression(
n_samples=10_000,
n_features=10,
)
这个
scikit-learn
示例没有明确的详细程度控制...
model = lgb.LGBMRegressor(
num_boost_round=10,
num_leaves=31,
).fit(X, y)
...产生此输出...
.../python3.11/site-packages/lightgbm/engine.py:172: UserWarning: Found `num_boost_round` in params. Will use it instead of argument
_log_warning(f"Found `{alias}` in params. Will use it instead of argument")
[LightGBM] [Warning] num_iterations is set=10, num_boost_round=10 will be ignored. Current value: num_iterations=10
[LightGBM] [Info] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000106 seconds.
You can set `force_row_wise=true` to remove the overhead.
And if memory is not enough, you can set `force_col_wise=true`.
[LightGBM] [Info] Total Bins 2550
[LightGBM] [Info] Number of data points in the train set: 10000, number of used features: 10
[LightGBM] [Info] Start training from score -1.188321
...但是有详细控制...
warnings.filterwarnings("ignore", category=UserWarning)
model = lgb.LGBMRegressor(
num_boost_round=10,
num_leaves=31,
verbosity=-1
).fit(X, y)
...不产生任何日志输出。
同样,使用
train()
且没有详细程度控制...
model = lgb.train(
train_set=lgb.Dataset(X, label=y),
params={
"objective": "regression",
"num_iterations": 10,
"num_leaves": 31
}
)
...产生这个输出...
.../python3.11/site-packages/lightgbm/engine.py:172: UserWarning: Found `num_iterations` in params. Will use it instead of argument
_log_warning(f"Found `{alias}` in params. Will use it instead of argument")
[LightGBM] [Info] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000136 seconds.
You can set `force_row_wise=true` to remove the overhead.
And if memory is not enough, you can set `force_col_wise=true`.
[LightGBM] [Info] Total Bins 2550
[LightGBM] [Info] Number of data points in the train set: 10000, number of used features: 10
[LightGBM] [Info] Start training from score -1.188321
...但是有详细控制...
warnings.filterwarnings("ignore", category=UserWarning)
model = lgb.train(
train_set=lgb.Dataset(X, label=y),
params={
"objective": "regression",
"num_iterations": 10,
"num_leaves": 31,
"verbosity": -1
}
)
...不产生任何日志输出。