## Developer Guide and Reference

• 2021.6
• 04/11/2022
• Public Content
Contents

# Naïve Bayes Classifier

Naïve Bayes is a set of simple and powerful classification methods often used for text classification, medical diagnosis, and other classification problems. In spite of their main assumption about independence between features, Naïve Bayes classifiers often work well when this assumption does not hold. An advantage of this method is that it requires only a small amount of training data to estimate model parameters.

## Details

The library provides Multinomial Naïve Bayes classifier [Renie03].
Let be the number of classes, indexed . The integer-valued feature vector , , contains scaled frequencies: the value of is the number of times the -th feature is observed in the vector (in terms of the document classification problem, is the number of occurrences of the word indexed in the document . For a given data set (a set of documents), , the problem is to train a Naïve Bayes classifier.
Training Stage
The Training stage involves calculation of these parameters:
• , where is the number of occurrences of the feature in the class , is the total number of occurrences of all features in the class, the (for example, ), and is the sum of all .
• , where is the prior class estimate.
Prediction Stage
Given a new feature vector , the classifier determines the class the vector belongs to:

## Computation

The following computation modes are available:

## Examples

C++ (CPU)
Batch Processing:
Online Processing:
Distributed Processing:
Java*
There is no support for Java on GPU.
Batch Processing:
Online Processing:
Distributed Processing:
Python*
Batch Processing:
Online Processing:
Distributed Processing:

## Performance Considerations

Training Stage
• If input data is homogeneous:
• For the training data set, use a homogeneous numeric table of the same type as specified in the algorithmFPType class template parameter.
• For class labels, use a homogeneous numeric table of type int.
• If input data is non-homogeneous, use AOS layout rather than SOA layout.
The training stage of the Naïve Bayes classifier algorithm is memory access bound in most cases. Therefore, use efficient data layout whenever possible.
Prediction Stage