Function File: C = cvpartition (X, [partition_type, [k]])

Create a partition object for cross validation.

X may be a positive integer, interpreted as the number of values n to partition, or a vector of length n containing class designations for the elements, in which case the partitioning types KFold and HoldOut attempt to ensure each partition represents the classes proportionately.

partition_type must be one of the following:

KFold

Divide set into k equal-size subsets (this is the default, with k=10).

HoldOut

Divide set into two subsets, "training" and "validation". If k is a fraction, that is the fraction of values put in the validation subset; if it is a positive integer, that is the number of values in the validation subset (by default k=0.1).

LeaveOut

Leave-one-out partition (each element is placed in its own subset).

resubstitution

Training and validation subsets that both contain all the original elements.

Given

Subset indices are as given in X.

The following fields are defined for the ‘cvpartition’ class:

classes

Class designations for the elements.

inds

Subset indices for the elements.

n_classes

Number of different classes.

NumObservations

n, number of elements in data set.

NumTestSets

Number of testing subsets.

TestSize

Number of elements in (each) testing subset.

TrainSize

Number of elements in (each) training subset.

Type

Partition type.

See also: crossval.

Demonstration 1

The following code

 # Partition with Fisher iris dataset (n = 150)
 # Stratified by species
 load fisheriris.txt
 y = fisheriris(:, 1);
 # 10-fold cross-validation partition
 c = cvpartition (y, 'KFold', 10)
 # leave-10-out partition
 c1 = cvpartition (y, 'HoldOut', 10)
 idx1 = test (c, 2);
 idx2 = training (c, 2);
 # another leave-10-out partition
 c2 = repartition (c1)

Produces the following output

warning: load: '/home/nir/Documents/octave-hg/octave-statistics/target/.installation/statistics-1.4.3/fisheriris.txt' found by searching load path
warning: called from
    get_output at line 50 column 5
    __html_help_text__ at line 67 column 28
    generate_package_html>wrote_html at line 842 column 5
    generate_package_html at line 207 column 7

K-fold cross validation partition
          N: 150
NumTestSets: 10
  TrainSize: 135  135  135  135  135  135  135  135  135  135
   TestSize: 15  15  15  15  15  15  15  15  15  15
HoldOut cross validation partition
          N: 150
NumTestSets: 1
  TrainSize: 140
   TestSize: 10
HoldOut cross validation partition
          N: 150
NumTestSets: 1
  TrainSize: 140
   TestSize: 10

Package: statistics