Search code examples
pythonmachine-learningxgboostdecision-tree

xgboost.cv TypeError: cv() got multiple values for argument 'dtrain'


Im trying to manually test different hyperparameters for xgboost, but this error keeps coming. I'm not sure how im supplying multiple arguments to dtrain if it ends with a comma.

import xgboost as xgb
dtrain = xgb.DMatrix(X, label=y)
params = {'eta':[0.1]}
xgb_cv = xgb.cv(
    {'disable_default_eval_metric': 1},
    params,
    dtrain=dtrain,
    seed=1,
    nfold=5,
    custom_metric=f1_score
)

Solution

  • The signature for xgboost.cv is (params, dtrain, ...). So it thinks you're passing the metric-disabling-dict as params, the eta-dict as dtrain, and then trying to pass another dtrain by keyword. If disable_default_eval_metric is supposed to be another parameter, add it to the params dictionary that contains eta instead.