### Function Reference: `@cvpartition/cvpartition`

statistics: 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, @cvpartition/display

Source Code: @cvpartition/cvpartition

### Example: 1

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

    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