From Wikipedia:

In k-fold cross-validation, the original sample is randomly partitioned into k equal size subsamples.

I am working on a 10 fold cross validation project. I have a dataset that has 76 elements. It means that I can not have equal size partitions.

What are the approaches for remaining data (in my example 6 data)? Ignoring them, making a data 16 elements, 6 partitions have 11 elements or etc?


Usually the $k$-fold cross validation subsets have approximately equal size. It is just crucial that they don't overlap.

For example I just had a look at what WEKA does. Say that you have $N$ instances and $k$ folds, then $$ r = N \mod k $$ (the remainder of $N$ divided by $k$) is the number of surplus records. The first $r$ partitions will have $\lfloor N/k \rfloor + 1$ records, the other ones just $\lfloor N/k \rfloor$ instead

Regarding your example: $$N = 76 $$ $$k = 10 $$ $$ r = N \mod k = 6 $$

First $6$ partitions will have $ \lfloor N/k \rfloor + 1 = 7 + 1 = 8$ records, the other ones $ 7 $ instead.


As Simone said, it's usually not essential for each fold to be exactly the same size. It'd be perfectly reasonable to have six folds containing eight records and four containing seven records each. That's probably a better solution than having nine folds of size seven and shoving the excess into the last one.

10-fold cross validation is usually a pretty reasonable choice, but you should be aware that there are a passel of related approaches (see this thread), and some of those might better choices, depending on the particulars of your data set. For example, if your classes are very unbalanced, you may want to consider stratified cross-validation, which tries to distribute the classes evenly across the folds (e.g., if you have 16 examples of class A, they're ideally spread across all 10 folds, not lumped together into fold #1 and #2).

Some other schemes, like 5x2 CV, also have relatively nice properties if you're doing inference on the cross-validation results.


You may want to use kfoldcv function to calculate sample sizes for the k groups.

kfoldcv(k, N, nlevel=NULL)

k    number of groups.
N    total sample size.
nlevel   a vector of sample sizes for stratified sampling.

You will have to install the ipred package.


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.