Skip to content

cvpartition hasn't the same behavior of matlab version #227

@achengli

Description

@achengli

Hello,

I was using cvpartition when I saw that cvpartition in Octave using KFold = 10 is giving groups of random sizes while with matlab the result was groups of same size or almost the same size when the number of observations is not divisible by the number of partitions.

The code I tried:

rng (1); % for reproducibility
y = randi (30,1,50);
cpart = cvpartition (y, 'KFold', 10);
Stratified k-fold cross validation partition
          NumObservations: 50
              NumTestSets: 10
                TrainSize: [26 48 48 45 50 42 45 48 48 50]
                 TestSize: [24 2 2 5 0 8 5 2 2 0]
                 IsCustom: 0
                IsGrouped: 0
             IsStratified: 1

TrainSize and TestSize have arbitrary number of observations. Doing the same with matlab retrieves the following:

K-fold cross validation partition
   NumObservations: 50
       NumTestSets: 10
         TrainSize: 45  45  45  45  45  45  45  45  45  45
          TestSize: 5  5  5  5  5  5  5  5  5  5
          IsCustom: 0

I copied the y variable literally in matlab

The number of observations of TrainSize and TestSize is the same for each group.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions