This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Naive Bayes

Naive Bayes model with Gaussian, multinomial, or kernel predictors

Naive Bayes models assume that observations have some multivariate distribution given class membership, but the predictor or features composing the observation are independent. This framework can accommodate a complete feature set such that an observation is a set of multinomial counts.

To train a naive Bayes model, use fitcnb in the command-line interface. After training, predict labels or estimate posterior probabilities by passing the model and predictor data to predict.


Classification LearnerTrain models to classify data using supervised machine learning


expand all

fitcnbTrain multiclass naive Bayes model
compactCompact naive Bayes classifier
crossvalCross-validated naive Bayes classifier
kfoldEdgeClassification edge for observations not used for training
kfoldLossClassification loss for observations not used for training
kfoldfunCross validate function
kfoldMarginClassification margins for observations not used for training
kfoldPredictPredict response for observations not used for training
lossClassification error for naive Bayes classifier
resubLossClassification loss for naive Bayes classifiers by resubstitution
logPLog unconditional probability density for naive Bayes classifier
compareHoldoutCompare accuracies of two classification models using new data
edgeClassification edge for naive Bayes classifiers
marginClassification margins for naive Bayes classifiers
resubEdgeClassification edge for naive Bayes classifiers by resubstitution
resubMarginClassification margins for naive Bayes classifiers by resubstitution
predictPredict labels using naive Bayes classification model
resubPredictPredict resubstitution labels of naive Bayes classifier


ClassificationNaiveBayesNaive Bayes classification
CompactClassificationNaiveBayesCompact naive Bayes classifier
ClassificationPartitionedModelCross-validated classification model


Train Naive Bayes Classifiers Using Classification Learner App

Create and compare naive Bayes classifiers, and export trained models to make predictions for new data.

Supervised Learning Workflow and Algorithms

Understand the steps for supervised learning and the characteristics of nonparametric classification and regression functions.

Parametric Classification

Categorical response data

Naive Bayes Classification

The naive Bayes classifier is designed for use when predictors are independent of one another within each class, but it appears to work well in practice even when that independence assumption is not valid.

Plot Posterior Classification Probabilities

This example shows how to visualize classification probabilities for the Naive Bayes classification algorithm.


This example shows how to perform classification using discriminant analysis, naive Bayes classifiers, and decision trees.

Visualize Decision Surfaces of Different Classifiers

This example shows how to visualize the decision surface for different classification algorithms.