maeaec
maeaec

Reputation: 15

Sklearn GridSearchCV with XGBoost - parameters cv might not be used

I have a list of tuples, where a tuple has the structure (train_ids, test_ids). The list is inteded to be used as the 'cv' parameter for SKlearns GridSearchCV method with XGBoost. However, during training I'm experiencing the following error:

Parameters { "cv" } might not be used. 

This may not be accurate due to some parameters are only used in language binding
but passed down to XGBoost core. Or some parameters are not used but slip through
this verifciation.

Does XGBoost support the cv parameter? And if not, are there any work arounds or other common practices to deal with CV for time series classification?

Upvotes: 0

Views: 807

Answers (1)

afsharov
afsharov

Reputation: 5164

It looks like you have passed your list of tuples as parameters in the parameter grid of GridSearchCV. However, they would then be passed to XGBClassifier which does not support such a parameter.

You have to pass the list to the GridSearchCV as its cv parameter like so:

import xgboost
from sklearn.model_selection import GridSearchCV


clf = xgboost.XGBClassifier()

gridsearch = GridSearchCV(
    estimator=clf, 
    param_grid={...},  # here only hyperparameters of XGBClassifier
    cv=[(train_ids, test_ids)]  # <-- here your list of indices
)

This is how it's done and should fix your problem.

Upvotes: 2

Related Questions