www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SelectECOCModelFeaturesByComparingInSampleEdgesExample.m
%% Select ECOC Model Features by Comparing In-Sample Edges % The classifier edge measures the average of the classifier margins. One % way to perform feature selection is to compare training sample edges from % multiple models. Based solely on this criterion, the classifier with the % highest edge is the best classifier. %% % Load Fisher's iris data set. Define two data sets: % % * |fullX| contains all four 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 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); %% % The default SVM score is distance from the decision boundary. If you % specify to compute posterior probabilities, then the software uses % posterior probabilities as scores. %% % Estimate the training sample edge for each classifier. The quadratic % loss function operates on scores in the domain [0,1]. Specify to use % quadratic loss when aggregating the binary learners for both models. fullEdge = resubEdge(FullMdl,'BinaryLoss','quadratic') partEdge = resubEdge(PartMdl,'BinaryLoss','quadratic') %% % The edge for the classifier trained on the complete data set is greater, % suggesting that the classifier trained using every predictor has a % better in-sample fit.