Train a multiclass ECOC classifier, and then cross-validate the model using a customk-fold loss function.
Load Fisher’s iris data set. Specify the predictor dataX
, the response dataY
, and the order of the classes inY
.
Train and cross-validate an ECOC model using support vector machine (SVM) binary classifiers. Standardize the predictors using an SVM template, and specify the class order.
CVMdl
is aClassificationPartitionedECOC
model. By default, the software implements 10-fold cross-validation.
Compute the classification error (proportion of misclassified observations) for the validation-fold observations.
Examine the result when the cost of misclassifying a flower asversicolor
is10
and the cost of any other error is1
. Write a function namednoversicolor
that assigns a cost of1
for general misclassification and a cost of10
for misclassifying a flower asversicolor
.
If you use the live script file for this example, thenoversicolor
function is already included at the end of the file. Otherwise, you need to create this function at the end of your .m file or add it as a file on the MATLAB path.
Compute the mean misclassification error with thenoversicolor
cost.
This code creates the functionnoversicolor
.