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

    %% Determine Resubstitution Classification Error 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 trained |ClassificationNaiveBayes| classifier.
%%
% Estimate the in-sample proportion of misclassified observations.
L = resubLoss(Mdl,'LossFun','classiferror')
%%
% The naive Bayes classifier misclassifies 4% of the training observations.