NaiveBayes class

Naive Bayes classifier


A NaiveBayes object defines a Naive Bayes classifier. A Naive Bayes classifier assigns a new observation to the most probable class, assuming the features are conditionally independent given the class value.


NaiveBayesCreate NaiveBayes object


dispDisplay NaiveBayes classifier object
displayDisplay NaiveBayes classifier object
fitCreate Naive Bayes classifier object by fitting training data
posteriorCompute posterior probability of each class for test data
predictPredict class label for test data
subsasgnSubscripted reference for NaiveBayes object
subsrefSubscripted reference for NaiveBayes object


CIsNonEmptyFlag for non-empty classes
ClassLevelsClass levels
DistDistribution names
NClassesNumber of classes
NDimsNumber of dimensions
ParamsParameter estimates
PriorClass priors

Copy Semantics

Value. To learn how this affects your use of the class, see Comparing Handle and Value Classes in the MATLAB® Object-Oriented Programming documentation.


Predict the class label using the Naive Bayes classifier:

load fisheriris
Use the default Gaussian distribution and a confusion matrix:
O1 = fitNaiveBayes(meas,species);
C1 = O1.predict(meas);
cMat1 = confusionmat(species,C1) 
This returns:
cMat1 =

    50     0     0
     0    47     3
     0     3    47
Use the Gaussian distribution for features 1 and 3 and use the kernel density estimation for features 2 and 4:
O2 = fitNaiveBayes(meas,species,'dist',...
C2 = O2.predict(meas);
cMat2 = confusionmat(species,C2)
This returns:
cMat2 =

    50     0     0
     0    47     3
     0     3    47


[1] Mitchell, T. (1997) Machine Learning, McGraw Hill.

[2] Vangelis M., Ion A., and Geogios P. Spam Filtering with Naive Bayes - Which Naive Bayes? (2006) Third Conference on Email and Anti-Spam.

[3] George H. John and Pat Langley. Estimating continuous distributions in bayesian classifiers (1995) the Eleventh Conference on Uncertainty in Artificial Intelligence.

Was this topic helpful?