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

    %% Estimate the Test-Sample 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); % Class order
rng(1); % For reproducibility
%%
% Train an ECOC model using SVM binary classifiers and specify a 30%
% holdout sample. 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,'Holdout',0.30,'Learners',t,'ClassNames',classOrder);
CMdl = CVMdl.Trained{1};           % Extract trained, compact classifier
testInds = test(CVMdl.Partition);  % Extract the test indices
XTest = X(testInds,:);
YTest = Y(testInds,:);
%%
% |CVMdl| is a |ClassificationPartitionedECOC| model. It contains
% the property |Trained|, which is a 1-by-1 cell array holding a
% |CompactClassificationECOC| model that the software trained using the
% training set.
%%
% Estimate the test-sample edge.
e = edge(CMdl,XTest,YTest)
%%
% The estimated test sample margin average is approximately 0.45.