# How does caret split into CV folds? Can I avoid splitting randomly?

As I understand when setting trainControl(method="cv") in the caret package, my training set is is split into K folds for cross validation. How is this splitting done? I assume it is randomized and stratified?

But the train set has been "upsampled" and if the split is randomized there will be a data leak over the train and test folds. (which lead to a overfit of course.) So, how can I avoid that the split is randomized and stratified? I want the folds to be made of consecutive samples. Can that be achieved?

• Why not perform the train test split first and then CV over the train set? There will be no data leakage. – Sada93 Aug 3 '17 at 16:36
• @Sada93 First split the cv folds and then "upsample", you mean? Yes, that would be the smartest thing to do, however this was not coded by me personally. – Øystein Schønning-Johansen Aug 3 '17 at 16:52