www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreateEnsembleTemplateForECOCMulticlassLearningExample.m
%% Create an Ensemble Template for ECOC Multiclass Learning % Create an ensemble template for use in % <docid:stats_ug.bue3oc9 fitcecoc>. %% % Load the arrhythmia data set. load arrhythmia tabulate(categorical(Y)); rng(1); % For reproducibility %% % Some classes have small relative frequencies in the data. %% % Create a template for a GentleBoost ensemble of classification trees, and % specify to use a 100 learners and a shrinkage of 0.1. By default, % boosting grows stumps (i.e., one node having a set of leaves). Since % there are classes with small frequencies, the trees must be leafy enough % to be sensitive to the minority classes. Specify the minimum number of % leaf node observations to 3. tTree = templateTree('MinLeafSize',20); t = templateEnsemble('AdaBoostM1',100,tTree,'LearnRate',0.1); %% % All properties of the template objects are empty except for |Method| and % |Type|, and the corresponding properties of the name-value pair argument % values in the function calls. When you pass |t| to the training function, % the software fills in the empty properties with their respective default % values. %% % Specify |t| as a binary learner for an ECOC multiclass model. Train % using the default one-versus-one coding design. Mdl = fitcecoc(X,Y,'Learners',t); %% % % * |Mdl| is a |ClassificationECOC| multiclass model. % * |Mdl.BinaryLearners| is a 78-by-1 cell array of % |CompactClassificationEnsemble| models. % * |Mdl.BinaryLearners{j}.Trained| is a 100-by-1 cell array of |CompactClassificationTree| models, for |j| = 1,...,78. % % You can verify that one of the binary learners contains a weak learner % that isn't a stump by using |view|. view(Mdl.BinaryLearners{1}.Trained{1},'Mode','graph') %% % Display the in-sample (resubstitution) misclassification error. L = resubLoss(Mdl,'LossFun','classiferror')