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.


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$ – Piotr Rarus Feb 18 '20 at 9:54

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.