www.gusucode.com > stats 源码程序 matlab案例代码 > stats/DeterminekfoldCrossValidationLossOfECOCModelsExample.m

    %% Determine _k_-Fold Cross-Validation Loss of ECOC Models
%%
% Load Fisher's iris data set.

% Copyright 2015 The MathWorks, Inc.

load fisheriris
X = meas;
Y = categorical(species);
classOrder = unique(Y); % Class order
rng(1); % For reproducibility
%%
% Train an ECOC model using SVM binary classifiers, and specify to cross
% validate. It is good practice to standardize the predictors and define
% the class order. Specify to standardize the predictors using an SVM
% template.
t = templateSVM('Standardize',1);
CVMdl = fitcecoc(X,Y,'CrossVal','on','Learners',t,'ClassNames',classOrder);
%%
% |CVMdl| is a |ClassificationPartitionedECOC| model. By default, the
% software implements 10-fold cross validation. You can alter the number of
% folds using the |'KFold'| name-value pair argument.
%%
% Estimate the average out-of-fold classification error.
L = kfoldLoss(CVMdl)
%%
% The average classification error for the folds is 4%. 
%%
% Alternatively, you can obtain the per-fold losses by specifying the
% name-value pair |'Mode','individual'| in |kfoldLoss|.