www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TrainECOCClassifiersUsingACustomCodingDesignExample.m
%% Train ECOC Classifiers Using a Custom Coding Design % Consider the |arrhythmia| data set. There are 16 classes in the study, % 13 of which are represented in the data. The first class indicates that % the subject did not have arrhythmia, and the last class indicates that % the subject's arrhythmia state was not recorded. Suppose that the other % classes are ordinal levels indicating the severity of arrhythmia. % Train an ECOC classifier using a custom coding design specified by the % description of the classes. %% % Load the |arrhythmia| data set. % Copyright 2015 The MathWorks, Inc. load arrhythmia K = 13; % Number of distinct classes %% % Construct a coding matrix that describes the nature of the classes. OrdMat = designecoc(11,'ordinal'); nOM = size(OrdMat); class1VSOrd = [1; -ones(11,1); 0]; class1VSClass16 = [1; zeros(11,1); -1]; OrdVSClass16 = [0; ones(11,1); -1]; Coding = [class1VSOrd class1VSClass16 OrdVSClass16,... [zeros(1,nOM(2)); OrdMat; zeros(1,nOM(2))]] %% % Train an ECOC classifier using the custom coding design |Coding| and % specify that the binary learners are decision trees. Mdl = fitcecoc(X,Y,'Coding',Coding,'Learner','Tree'); %% % Estimate the in-sample classification error. genErr = resubLoss(Mdl)