Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

**Class: **cvpartition

Create cross-validation partition for data

`c = cvpartition(n,'KFold',k)`

`c = cvpartition(n,'HoldOut',p)`

`c = cvpartition(group,'KFold',k)`

`c = cvpartition(group,'KFold',k,'Stratify',stratifyOption)`

`c = cvpartition(group,'HoldOut',p)`

`c = cvpartition(group,'HoldOut',p,'Stratify',stratifyOption)`

`c = cvpartition(n,'LeaveOut')`

`c = cvpartition(n,'resubstitution')`

constructs an object `c`

= cvpartition(`n`

,`'KFold'`

,k)`c`

of the `cvpartition`

class defining a random
nonstratified partition for `k`

-fold cross-validation on
`n`

observations. The partition divides the observations
into `k`

disjoint subsamples (or *folds*), chosen randomly but with roughly
equal size. The default value of `k`

is
`10`

.

creates a random nonstratified partition for holdout validation on
`c`

= cvpartition(`n`

,`'HoldOut'`

,p)`n`

observations. This partition divides the observations
into a training set and a test (or *holdout*) set. The parameter
`p`

must be a scalar. When `0`

<
`p`

< `1`

,
`cvpartition`

randomly selects approximately
`p*n`

observations for the test set. When
`p`

is an integer, `cvpartition`

randomly selects `p`

observations for the test set. The default
value of `p`

is `1/10`

.

creates a random partition for a stratified `c`

= cvpartition(`group`

,`'KFold'`

,k)`k`

-fold
cross-validation. `group`

is a numeric vector, categorical
array, character array, string array, or cell array of character vectors
indicating the class of each observation. Each subsample has roughly equal size
and roughly the same class proportions as in `group`

.

When you supply `group`

as the first input argument to
`cvpartition`

, the function creates cross-validation
partitions that do not include rows of observations corresponding to missing
values in `group`

.

returns an object `c`

= cvpartition(`group`

,`'KFold'`

,k,`'Stratify'`

,stratifyOption)`c`

defining a random partition for
`k`

-fold cross-validation. When you supply
`group`

as the first input argument to
`cvpartition`

, then the function implements
stratification by default. If you also specify
`'Stratify',false`

, then the function creates nonstratified
random partitions.

You can specify `'Stratify',true`

only if the first input
argument to `cvpartition`

is
`group`

.

randomly partitions observations into a training set and a holdout (or test) set
with stratification, using the class information in `c`

= cvpartition(`group`

,`'HoldOut'`

,p)`group`

.
Both the training and test sets have roughly the same class proportions as in
`group`

.

returns an object `c`

= cvpartition(`group`

,`'HoldOut'`

,p,`'Stratify'`

,stratifyOption)`c`

defining a random partition into a
training set and a holdout (or test) set. When you supply
`group`

as the first input argument to
`cvpartition`

, then the function implements
stratification by default. If you also specify
`'Stratify',false`

, then the function creates nonstratified
random partitions.

`c = cvpartition(n,'LeaveOut')`

creates a random partition
for leave-one-out cross-validation on `n`

observations.
Leave-one-out is a special case of `'KFold'`

in which the
number of folds equals the number of observations.

`c = cvpartition(n,'resubstitution')`

creates an object
`c`

that does not partition the data. Both the training set
and the test set contain all of the original `n`

observations.

If you supply

`group`

as the first input argument to`cvpartition`

, the function creates cross-validation partitions that do not include rows of observations corresponding to missing values in`group`

.When you supply

`group`

as the first input argument to`cvpartition`

, then the function implements stratification by default. You can specify`'Stratify',false`

to create nonstratified random partitions.You can specify

`'Stratify',true`

only if the first input argument to`cvpartition`

is`group`

.