0
$\begingroup$

Here is the explain of cv parameter in the sklearn.model_selection.GridSearchCV:

cv : int, cross-validation generator or an iterable, optional

Determines the cross-validation splitting strategy. Possible inputs for cv are:

  • integer, to specify the number of folds in a (Stratified)KFold

For example, can I replace

CV = 5

to

CV = KFold(n_splits=5, random_state=None, shuffle=False)

or replace in the opposite way. CV is called in the function

GridSearchCV(estimator=XXX, ... , cv = CV)

I am not sure whether any difference?

$\endgroup$
3
$\begingroup$

Yes, you can replace the cv=5 with cv=KFold(n_splits=5, random_state=None, shuffle=False). Leaving it set to an integer, like 5, is the equivalent of setting it to either KFold(n_splits=5) or StratifiedKFold(n_splits=5), depending on the model you pass to the estimator parameter of GridSearchCV()

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.