我尝试在 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)
关于python - Xgboost 中的意外参数 'eval_metric',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49214530/