www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimateInSampleClassificationMarginsOfNaiveBayesClassifExample.m
%% Estimate In-Sample Classification Margins of Naive Bayes Classifiers %% % Load Fisher's iris data set. % Copyright 2015 The MathWorks, Inc. load fisheriris X = meas; % Predictors Y = species; % Response %% % Train a naive Bayes classifier. It is good practice to specify the class % order. Assume that each predictor is conditionally, normally distributed % given its label. Mdl = fitcnb(X,Y,'ClassNames',{'setosa','versicolor','virginica'}); %% % |Mdl| is a |ClassificationNaiveBayes| classifier. %% % Estimate the in-sample classification margins. Display the distribution % of the margins using a boxplot. m = resubMargin(Mdl); figure; boxplot(m); h = gca; iqr = quantile(m,0.75) - quantile(m,0.25); h.YLim = median(m) + iqr*[-4 4]; title 'Boxplot of the Margins'; %% % An observation margin is the observed (true) class score minus the maximum % false class score among all scores in the respective class. Classifiers % that yield relatively large margins are desirable.