www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SelectECOCModelFeaturesByExaminingInSampleMarginsExample.m
%% Select ECOC Model Features by Examining In-Sample Margins % The classifier margins measure, for each observation, the difference % between the positive-class, negated loss score and the maximal % negative-class, negated loss. One way to perform feature selection is to % compare in-sample margins from multiple models. Based solely on this % criterion, the model with the highest margins is the best model. %% % Load Fisher's iris data set. Define two data sets: % % * |fullX| contains all 4 predictors. % * |partX| contains the sepal measurements. % % Copyright 2015 The MathWorks, Inc. load fisheriris X = meas; fullX = X; partX = X(:,1:2); Y = species; %% % Train ECOC models using SVM binary learners for each predictor set. It is % good practice to standardize the predictors and define the class order. % Specify to standardize the predictors using an SVM template, and to % compute posterior probabilities. t = templateSVM('Standardize',1); classOrder = unique(Y) FullMdl = fitcecoc(fullX,Y,'Learners',t,'ClassNames',classOrder,... 'FitPosterior',1); PartMdl = fitcecoc(partX,Y,'Learners',t,'ClassNames',classOrder,... 'FitPosterior',1); %% % Estimate the in-sample margins for each classifier. For each model, % display the distribution of the margins using a boxplot. fullMargins = resubMargin(FullMdl); partMargins = resubMargin(PartMdl); figure; boxplot([fullMargins partMargins],'Labels',{'All Predictors','Two Predictors'}); title('Boxplots of In-Sample Margins') %% % The margin distribution of CMdl is situated higher, and with less % variablility than the margin distribution of PCMdl.