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

    %% Train a Multiclass Model Using SVM Learners
% Train an error-correcting output codes (ECOC) multiclass model using
% support vector machine (SVM) binary learners.
%%
% Load Fisher's iris data set.

% Copyright 2015 The MathWorks, Inc.

load fisheriris
X = meas;
Y = species;
%%
% Train an ECOC multiclass model using the default options.
Mdl = fitcecoc(X,Y)
%%
% |Mdl| is a |ClassificationECOC| model.  By default, |fitcecoc| uses SVM
% binary learners, and uses a one-versus-one coding design. You can access
% |Mdl| properties using dot notation.
%%
% Display the coding design matrix.
Mdl.ClassNames
CodingMat = Mdl.CodingMatrix
%% 
% A one-versus-one coding design on three classes yields three binary
% learners.  Columns of |CodingMat| correspond to learners and rows 
% correspond to classes.  The class order corresponds to the order
% in |Mdl.ClassNames|. For example, |CodingMat(:,1)| is |[1; -1; 0]|, and  
% indicates that the software trains the first SVM binary learner using
% all observations classified as |'setosa'| and |'versicolor'|.  Since
% |'setosa'| corresponds to |1|, it is the positive class, and since
% |'versicolor'| corresponds to |-1|, it is the negative class.
%%
% You can access each binary learner using cell indexing and dot notation.
Mdl.BinaryLearners{1}                % The first binary learner
Mdl.BinaryLearners{1}.SupportVectors % Support vector indices
%%
% Compute the in-sample classification error.
isLoss = resubLoss(Mdl)
%%
% The classification error is small, but the classifier might have been
% overfit.  You can cross validate the classifier using |crossval|.