File Exchange

image thumbnail

Naive Bayes (NB) Classifier

version 1.1.7 (3.17 KB) by David Ferreira
Multi-class Classification with the NB


Updated 10 Nov 2020

From GitHub

View Version History

View license on GitHub

1. NaiveBayes.predict(_)
2. NaiveBayes.find(_)

1. Returns the estimated labels of one or multiple test instances and the accuracy of the estimates.
2. Returns the labels with their respective probabilities in descending order.

Examples using Iris Data Set

load fisheriris

X = meas;
Y = species;
Xnew = [min(X);mean(X);max(X)];

mdl = NaiveBayes('gaussian');
mdl =,Y)
Ypred = mdl.predict(Xnew)

Ypred =


Ynew = {'versicolor';'versicolor';'virginica'};
accuracy = accuracy_score(Ypred,Ynew)

accuracy =


See more examples described in the script files.

Cite As

David Ferreira (2021). Naive Bayes (NB) Classifier (, GitHub. Retrieved .

Comments and Ratings (2)

Huang Darren

Chang hsiung

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!