Main Content

repartition

Repartition data for cross-validation

Description

cnew = repartition(c) creates a cvpartition object cnew that defines a random partition of the same type as c, where c is also a cvpartition object. That is, repartition takes the same observations in c and repartitions them into new training and test sets.

example

cnew = repartition(c,s) uses the RandStream object s as the random number generator for the new partition.

Examples

collapse all

Repartition observations in a cvpartition object. The type of validation partition remains the same.

Partition 100 observations for 3-fold cross-validation.

c = cvpartition(100,'KFold',3)
c = 
K-fold cross validation partition
   NumObservations: 100
       NumTestSets: 3
         TrainSize: 67  66  67
          TestSize: 33  34  33
          IsCustom: 0

Repartition the observations.

cnew = repartition(c)
cnew = 
K-fold cross validation partition
   NumObservations: 100
       NumTestSets: 3
         TrainSize: 67  66  67
          TestSize: 33  34  33
          IsCustom: 0

Notice that the set of observations in the first test set (fold) of c is not the same as the set of observations in the first test set of cnew.

isequal(test(c,1),test(cnew,1))
ans = logical
   0

View the validation partition type of c and cnew. Both c and cnew are validation partitions of the same type, 'kfold'.

isequal(c.Type,cnew.Type)
ans = logical
   1

c.Type
ans = 
'kfold'

Input Arguments

collapse all

Validation partition, specified as a cvpartition object. The validation partition type of c, c.Type, is the same as the validation partition type of the new partition cnew.

The function supports repartitioning only when the c.IsCustom property is 0 (false).

Random number generator for the new partition, specified as a RandStream object.

Tips

  • Repartitioning is useful for Monte Carlo repetitions of cross-validation analyses. crossval calls repartition when you specify the MCReps name-value argument.

Version History

Introduced in R2008a