FUNCTION REFERENCE
crossval
Refit a classifier on randomized training and validation partitions.
Refit a classifier on randomized training and validation partitions.
Syntax
cvmdl = crossval(mdl)Syntax
cvmdl = crossval(mdl,'KFold',k)Syntax
cvmdl = crossval(mdl,'Holdout',p)Syntax
cvmdl = crossval(mdl,'Leaveout','on')Syntax
cvmdl = crossval(mdl,'CVPartition',c)Returns a ClassificationPartitionedModel. The default is 10 folds; KFold must be between 2 and the observation count. A Fisher-Yates shuffle consumes the session rng stream. Holdout reserves ceil(p*NumObservations) observations, leaving at least one for training. Each fold refits the original classifier options and standardization on training rows only. Use kfoldPredict and kfoldLoss to evaluate held-out observations.
Example
rng(0); m=fitcknn((1:10)',[ones(5,1);2*ones(5,1)]); cv=crossval(m); loss=kfoldLoss(cv)Differences from MATLAB: class-stratified partitions and supplied CVPartition objects are supported. Only classifier-model input is supported; function input is unsupported. Folds lacking the two classes needed by SVM error explicitly. Retained folds are bounded to 1000 and 8000000 predictor elements in total.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.