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

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

% Copyright 2015 The MathWorks, Inc.

load fisheriris
X = meas;
Y = categorical(species);
classOrder = unique(Y);
rng(1); % For reproducibility
%%
% Train an ECOC model using SVM binary classifiers and specify to cross
% validate. It is good practice to 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 |ClassificationPartitionedModel| 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 of the out-of-fold edges.
edge = kfoldEdge(CVMdl)
%%
% Alternatively, you can obtain the per-fold edges by specifying the
% name-value pair |'Mode','individual'| in |kfoldEdge|.