www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SelectSVMClassifierFeaturesByExaminingInSampleMarginsExample.m
%% Select SVM Classifier Features by Examining In-Sample Margins % The classifier margins measure, for each observation, the difference % between the true class observed score and the maximal false class score % for a particular class. 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 the |ionosphere| data set. Define two data sets: % % * |fullX| contains all predictors (except the removed column of 0s). % * |partX| contains the last 20 predictors. % % Copyright 2015 The MathWorks, Inc. load ionosphere fullX = X; partX = X(:,end-20:end); %% % Train SVM classifiers for each predictor set. FullSVMModel = fitcsvm(fullX,Y); PartSVMModel = fitcsvm(partX,Y); %% % Estimate the in-sample margins for each classifier. fullMargins = resubMargin(FullSVMModel); partMargins = resubMargin(PartSVMModel); n = size(X,1); p = sum(fullMargins < partMargins)/n %% % Approximately 22% of the margins from the full model are less than those % from the model with fewer predictors. This suggests that the model % trained using all of the predictors is better.