python - Xgboost 中的意外参数 'eval_metric'

标签 python machine-learning 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)

关于python - Xgboost 中的意外参数 'eval_metric',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49214530/

相关文章:

python - Pandas 映射到 TRUE/FALSE 作为字符串,而不是 bool 值

android - 如何解析 "adb shell top"以仅显示 CPU 或内存使用情况?

python - 我可以使用 Tkinter 创建 Tcl 交互式 shell 吗?

python - 连接包含列表的两列python

matplotlib - 如何计算回归预测的置信区间?以及如何在 python 中绘制它

machine-learning - XGBoost 模型上的 GridSearchCV 给出错误

python - XGBoost 中的绘图编号格式plot_importance()

python - 未在 featuretools 中为我的实体集设置生成功能

machine-learning - Keras:多类 NLP 任务中 model.evaluate 与 model.predict 的准确性差异

python - XGboost - 网格搜索无法正常工作