使用 LGBMClassifier.fit() 时,参数 early_stopping_rounds 出现报错。
原因是,LGBMClassifier.fit() 不直接接受 early_stopping_rounds 参数,而需要通过 callbacks 来实现早停功能。

报错信息如下:

TypeError: LGBMClassifier.fit() got an unexpected keyword argument ‘early_stopping_rounds’

调整:

# 模型训练函数中不再支持early_stopping_rounds参数
gbm.fit(X_train, y_train, eval_set=[(X_test, y_test)], early_stopping_rounds=5)

需要修改为:

from lightgbm import early_stopping
callbacks = [early_stopping(stopping_rounds=5)]
gbm.fit(X_train, y_train, eval_set=[(X_test, y_test)],callbacks=callbacks)
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐