XGBClassifier.fit() got an unexpected keyword argument 'early_stopping_rounds'

XGBClassifier.fit() got an unexpected keyword argument 'early_stopping_rounds'

阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程
问题解答
XGBClassifier.fit()方法中没有early_stopping_rounds参数,这个参数实际上是XGBRegressor和XGBRanker中的参数,而不是XGBClassifier的参数。
如果你想实现early stopping,可以使用XGBRegressor或XGBRanker,并使用early_stopping_rounds参数。例如:
xgb_regressor = XGBRegressor(objective='reg:squarederror', max_depth=6, learning_rate=0.1)
xgb_regressor.fit(X_train, y_train, early_stopping_rounds=5, eval_set=[(X_val, y_val)], eval_metric='rmse')
如果你想使用XGBClassifier,可以使用其他early stopping方法,例如使用validation set和 patience参数来实现early stopping。例如:
xgb_clf = XGBClassifier(objective='binary:logistic', max_depth=6, learning_rate=0.1)
xgb_clf.fit(X_train, y_train, eval_set=[(X_val, y_val)], eval_metric='auc', early_stopping_rounds=5)
注意:XGBClassifier中没有early_stopping_rounds参数,因此你不能使用这个参数。