www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SelectNaiveBayesClassifierFeaturesByComparingInSampleEdgExample.m

    %% Select Naive Bayes Classifier 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 predictors.
% * |partX| contains the last two predictors.
%

% Copyright 2015 The MathWorks, Inc.

load fisheriris
X = meas;    % Predictors
Y = species; % Response
fullX = X;
partX = X(:,3:4);
%%
% Train naive Bayes classifiers for each predictor set.
FullMdl = fitcnb(fullX,Y);
PartMdl = fitcnb(partX,Y);
%%
% Estimate the training sample edge for each classifier.
fullEdge = resubEdge(FullMdl)
partEdge = resubEdge(PartMdl)
%%
% The edge for the classifier trained on predictors 3 and 4 is greater,
% suggesting that the classifier trained using only those predictors has a
% better in-sample fit.