提问人:LVN 提问时间:9/19/2023 最后编辑:James LambLVN 更新时间:9/21/2023 访问量:452
LightGBM 中的early_stopping_rounds
early_stopping_rounds in lightgbm
问:
嗨,我在 VS 代码中使用 Python 包时遇到了问题:lightgbm
import lightgbm as lgb
parameters = {
'application': 'binary',
'objective': 'binary',
'metric': 'auc',
'is_unbalance': 'true',
'boosting': 'gbdt',
'num_leaves': 50,#31,
'feature_fraction': 0.8,
'bagging_fraction': 0.8,
'bagging_freq': 20,
'learning_rate': 0.003,
'max_depth': 5,
'verbose': 0
}
model = lgb.train(
parameters,
train_data_lgb,
valid_sets=test_data_lgb,
num_boost_round=3000,
early_stopping_rounds=100
)
错误是:
TypeError Traceback (most recent
call last)
c:\Users\lvn06\Desktop\ML bootcamp\Sesión 5\2. Bagging y Boosting - Clasificación.ipynb Cell 178 line 1
----> 1 model = lgb.train(parameters,
2 train_data_lgb,
3 valid_sets=test_data_lgb,
4 num_boost_round=3000,
5 early_stopping_rounds=100)
TypeError: train() got an unexpected keyword argument 'early_stopping_rounds'
我一直在寻找解决方案,但没有找到任何解决方案。
答:
0赞
James Lamb
9/20/2023
#1
该错误消息表明您正在使用 .删除了对关键字参数的支持 (microsoft/LightGBM#4908lightgbm>=4.0.0
early_stopping_rounds
lightgbm.train()
lightgbm==4.0.0
)
使用 ,传递验证集和回调,如以下二元分类示例所示:lightgbm>=4.0.0
lightgbm.early_stopping()
import lightgbm as lgb
from sklearn.datasets import make_blobs
from sklearn.model_selection import train_test_split
X, y = make_blobs(n_samples=10_000, centers=2)
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8)
dtrain = lgb.Dataset(X_train, label=y_train)
dvalid = lgb.Dataset(X_valid, label=y_valid)
model = lgb.train(
params={
"objective": "binary",
"metric": "auc",
},
train_set=dtrain,
valid_sets=[dvalid],
num_boost_round=10,
callbacks=[
lgb.early_stopping(stopping_rounds=3),
]
)
通过将参数修改为 来更改轮数。stopping_rounds
lgb.early_stopping()
下一个:如何仅获取字段名称的值?
评论
lgb
train_data_lgb
test_data_lgb
params
num_boost_round