www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimatekFoldCrossValidationMarginsOfECOCModelsExample.m
%% Estimate _k_-Fold Cross-Validated Margins 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 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 |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 out-of-fold margins. Display the distribution of the % mnargins using a boxplot. margin = kfoldMargin(CVMdl); figure; boxplot(margin); title('Cross-Validated Margins') %% % An observation margin is the positive-class, negated loss minus the % maximum negative-class, negated loss. Classifiers that yield relatively % large margins are desirable.