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. You can
be use this partition to define test and training sets for validating
a statistical model using cross-validation.
Construction
Methods
| disp | Display cvpartition object |
| display | Display cvpartition object |
| repartition | Repartition data for cross-validation |
| test | Test indices for cross-validation |
| training | Training indices for cross-validation |
Properties
| N | Number of observations (including observations with missing group values) |
| NumTestSets | Number of test sets |
| TestSize | Size of each test set |
| TrainSize | Size of each training set |
| Type | Type 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
Grouped Data
crossval
 | cutvar (classregtree) | | cvpartition |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit