Documentation Center

  • Trial Software
  • Product Updates

cvpartition class

Data partitions for cross validation

Description

An object of the cvpartition class defines a random partition on a set of data of a specified size. Use this partition to define test and training sets for validating a statistical model using cross validation.

Construction

cvpartitionCreate cross validation partition for data

Methods

dispDisplay cvpartition object
displayDisplay cvpartition object
repartitionRepartition data for cross-validation
testTest indices for cross-validation
trainingTraining indices for cross-validation

Properties

NNumber of observations (including observations with missing group values)
NumTestSetsNumber of test sets
TestSizeSize of each test set
TrainSizeSize of each training set
TypeType of partition

Copy Semantics

Value. To learn how this affects your use of the class, see Comparing Handle and Value Classes in the MATLAB® Object-Oriented Programming documentation.

Examples

Use a 10-fold stratified cross validation to compute the misclassification error for classify on iris data.

load('fisheriris');
CVO = cvpartition(species,'k',10);
err = zeros(CVO.NumTestSets,1);
for i = 1:CVO.NumTestSets
    trIdx = CVO.training(i);
    teIdx = CVO.test(i);
    ytest = classify(meas(teIdx,:),meas(trIdx,:),...
		 species(trIdx,:));
    err(i) = sum(~strcmp(ytest,species(teIdx)));
end
cvErr = sum(err)/sum(CVO.TestSize);

See Also

How To

Was this topic helpful?