Xgboost 中的意外参数 'eval_metric'

unexpected argument 'eval_metric' in Xgboost

我尝试在 XgBoost 中使用 eval_metric 参数但出现此错误:

TypeError: fit() got an unexpected keyword argument 'eval_metric'

这是我的代码:

eval_set = [(X_test_np, y_test_np)]
model = XGBClassifier()
model.fit(X_train_np, y_train_np,eval_metric="auc", eval_set=eval_set)

有人知道这个问题的解决方法吗?

我使用 xgb 的方式有点不同。下面的代码会让你对你的超参数有一些控制,如果事情不起作用,我会帮助你

import xgboost as xgb

dtrain = xgb.DMatrix(X_train_np, label=y_train_np)
dtest = xgb.DMatrix(X_test_np, label=y_test_np)

# Here we set eval_metric to be 'auc' as well as other hypter parameters of xgboost
param0 = [
    ('max_depth', 4),
    ('eta', 0.1),
    ('objective', 'binary:logistic'),
    ('min_child_weight', 4),
    ('silent', 1),
    ('eval_metric', 'auc'),
    ('subsample', 0.75),
    ('colsample_bytree', 0.75),
    ('gamma', 1),
]

watchlist = [(dtrain, "trn"), (dtest, "tst")]
n_estimators = 100

# This is the same as fitting
model = xgb.train(param0, dtrain, n_estimators , evals=watchlist)