Main Content

crossval

Class:ClassificationDiscriminant

Cross-validated discriminant analysis classifier

Syntax

cvmodel= crossval(obj)
cvmodel= crossval(obj,Name,Value)

Description

cvmodel= crossval(obj)creates a partitioned model fromobj, a fitted discriminant analysis classifier. By default,crossvaluses 10-fold cross validation on the training data to createcvmodel.

cvmodel= crossval(obj,Name,Value)creates a partitioned model with additional options specified by one or moreName,Valuepair arguments.

Input Arguments

obj

Discriminant analysis classifier, produced usingfitcdiscr.

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

CVPartition

Object of classcvpartition, created by thecvpartitionfunction.crossvalsplits the data into subsets withcvpartition.

Use only one of these options at a time:'CVPartition','Holdout','KFold', or'Leaveout'.

Default:[]

Holdout

Holdout validation tests the specified fraction of the data, and uses the rest of the data for training. Specify a numeric scalar from0to1. Use only one of these options at a time:'CVPartition','Holdout','KFold', or'Leaveout'.

KFold

Number of folds to use in a cross-validated classifier, a positive integer value greater than 1.

Use only one of these options at a time:'CVPartition','Holdout','KFold', or'Leaveout'.

Default:10

Leaveout

Set to'on'for leave-one-out cross validation.

Use only one of these options at a time:'CVPartition','Holdout','KFold', or'Leaveout'.

Examples

Create a classification model for the Fisher iris data, and then create a cross-validation model. Evaluate the quality the model usingkfoldLoss.

load fisheriris obj = fitcdiscr(meas,species); cvmodel = crossval(obj); L = kfoldLoss(cvmodel) L = 0.0200

Tips

  • Assess the predictive performance ofobjon cross-validated data using the “kfold” methods and properties ofcvmodel, such askfoldLoss.

Alternatives

You can create a cross-validation classifier directly from the data, instead of creating a discriminant analysis classifier followed by a cross-validation classifier. To do so, include one of these options infitcdiscr:'CrossVal','CVPartition','Holdout','KFold', or'Leaveout'.