For my Strategy that I'm using is doing the cross validation on medical information from 10 patient. So what I am doing is split 1 subject to be validation set and 8 subjects are training sets. And I've implement this problem on gridsearchCV. But the problem is i don't want to perform n-fold cross validation given by gridsearchCV. And i have store my data from into an array

in this pattern : [subject1_dataframe, subject2_dataframe, ..., subject10_dataframe]

And I want to use GridSearchCV to perform the validation by splitting the training set and validation set automatically. What i've try is "PredefinedSplit" that can split by using index but my next problem is my dataset store in array following the above pattern. And gridsearchCV cannot work with this pattern.

Any suggestion to solve this problem?

Is there another ways to optimized the parameters like gridsearchCV and can specific the validation set by myself?

Thank you


1 Answer 1


Merge your dataframes into a single one using pandas.concat, with axis=0 and ignore_index=True (so that it doesn't use local indices). Make sure they've the same column names, and if not, standardize your columns, because you'll have to deal with a bunch of NaNs and extra columns. Then, generate your fold indices accordingly, using PredefinedSplit or some other way, and input your interested param_grid. If you'll apply one of the listed methods here, they've CV wrappers around them. But, they still need modifications I described above. A whole another way is just simple manual looping throughout your parameter grid.

  • $\begingroup$ Yeah, I'm thinking about label each rows to each different fold and use the different label pass into predefinedsplit and perform a gridsearchCV. Is this the same idea to you right? Please Correct my understanding. Thank you gunes :) $\endgroup$ Mar 30, 2019 at 13:19
  • 1
    $\begingroup$ I suppose yes, but don’t forget to merge the dataframes into a single one. $\endgroup$
    – gunes
    Mar 30, 2019 at 16:16

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.