I have different image datasets, most of them are sorted by class, others are already mixed. For each of these data sets, I would like to train one SVM (in Python with Scikit-Learn), whereby in each case the hyperparameters are previously optimized using GridSearchCV. Some of the ordered data sets still need to be split into training and test data, which would then be in mixed form after using train_test_split and, to my understanding, would not have to be mixed again before using GridSearchCV.

Other ordered data sets are already split into training and test data, so I would directly apply GridSearchCV. Now I have found that StratifiedKFold does not mix the data before splitting into batches, if I understood correctly. In those cases, I should mix the data before using GridSearchCV, right?

If I am mistaken in my assumptions, I would be grateful for any hint.


1 Answer 1


GridSearchCV will not shuffle the data by default. However, as you noted, you can pass Kfold or StratifiedKfold objects to cv argument, that specify shuffling.

For example:

model = XGBClassifier()
param_grid = {"n_estimators": [100]}
cv = StratifiedKFold(n_splits=5, shuffle=True)
gs = GridSearchCV(model, param_grid=param_grid)
  • $\begingroup$ All selection cv objects are shuffled by default. You should always shuffle but provide specific random_seed so it can be reproduce. $\endgroup$ Feb 18, 2020 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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