Naive Bayes classifier


In statistics, naive 'Bayes classifiers are a family of "probabilistic classifiers" which assumes that the features are conditionally independent, given the target class. In other words, a naive Bayes model assumes the information about the class provided by each variable is unrelated to the information from the others, with no information shared between the predictors. The highly unrealistic nature of this assumption, called the naive independence assumption', is what gives the classifier its name. These classifiers are some of the simplest Bayesian network models.
Naive Bayes classifiers generally perform worse than more advanced models like logistic regressions, especially at quantifying uncertainty. However, they are highly scalable, requiring only one parameter for each feature or predictor in a learning problem. Maximum-likelihood training can be done by evaluating a closed-form expression, rather than the expensive iterative approximation algorithms required by most other models.
Despite the use of Bayes' theorem in the classifier's decision rule, naive Bayes is not a Bayesian method, and naive Bayes models can be fit to data using either Bayesian or frequentist methods.

Introduction

Naive Bayes is a simple technique for constructing classifiers: models that assign class labels to problem instances, represented as vectors of feature values, where the class labels are drawn from some finite set. There is not a single algorithm for training such classifiers, but a family of algorithms based on a common principle: all naive Bayes classifiers assume that the value of a particular feature is independent of the value of any other feature, given the class variable. For example, a fruit may be considered to be an apple if it is red, round, and about 10 cm in diameter. A naive Bayes classifier considers each of these features to contribute independently to the probability that this fruit is an apple, regardless of any possible correlations between the color, roundness, and diameter features.
In many practical applications, parameter estimation for naive Bayes models uses the method of maximum likelihood; in other words, one can work with the naive Bayes model without accepting Bayesian probability or using any Bayesian methods.
Despite their naive design and apparently oversimplified assumptions, naive Bayes classifiers have worked quite well in many complex real-world situations. In 2004, an analysis of the Bayesian classification problem showed that there are sound theoretical reasons for the apparently implausible efficacy of naive Bayes classifiers. Still, a comprehensive comparison with other classification algorithms in 2006 showed that Bayes classification is outperformed by other approaches, such as boosted trees or random forests.
An advantage of naive Bayes is that it only requires a small amount of training data to estimate the parameters necessary for classification.

Probabilistic model

Abstractly, naive Bayes is a conditional probability model: it assigns probabilities for each of the possible outcomes or classes given a problem instance to be classified, represented by a vector encoding some features.
The problem with the above formulation is that if the number of features is large or if a feature can take on a large number of values, then basing such a model on probability tables is infeasible. The model must therefore be reformulated to make it more tractable. Using Bayes' theorem, the conditional probability can be decomposed as:
In plain English, using Bayesian probability terminology, the above equation can be written as
In practice, there is interest only in the numerator of that fraction, because the denominator does not depend on and the values of the features are given, so that the denominator is effectively constant.
The numerator is equivalent to the joint probability model
which can be rewritten as follows, using the chain rule for repeated applications of the definition of conditional probability:
Now the "naive" conditional independence assumptions come into play: assume that all features in are mutually independent, conditional on the category. Under this assumption,
Thus, the joint model can be expressed as
where denotes proportionality since the denominator is omitted.
This means that under the above independence assumptions, the conditional distribution over the class variable is:
where the evidence is a scaling factor dependent only on, that is, a constant if the values of the feature variables are known.
Often, it is only necessary to discriminate between classes. In that case, the scaling factor is irrelevant, and it is sufficient to calculate the log-probability up to a factor:The scaling factor is irrelevant, since discrimination subtracts it away:There are two benefits of using log-probability. One is that it allows an interpretation in information theory, where log-probabilities are units of information in nats. Another is that it avoids arithmetic underflow.

Constructing a classifier from the probability model

The discussion so far has derived the independent feature model, that is, the naive Bayes probability model. The naive Bayes classifier combines this model with a decision rule. One common rule is to pick the hypothesis that is most probable so as to minimize the probability of misclassification; this is known as the maximum a posteriori or MAP decision rule. The corresponding classifier, a Bayes classifier, is the function that assigns a class label for some as follows:
File:ROC_curves.svg|thumb|Likelihood functions, Confusion matrix and ROC curve. For the naive Bayes classifier and given that the a priori probabilities are the same for all classes, then the decision boundary would be placed on the point where the two probability densities intersect, due to

Parameter estimation and event models

A class's prior may be calculated by assuming equiprobable classes, i.e.,, or by calculating an estimate for the class probability from the training set:
To estimate the parameters for a feature's distribution, one must assume a distribution or generate nonparametric models for the features from the training set.
The assumptions on distributions of features are called the "event model" of the naive Bayes classifier. For discrete features like the ones encountered in document classification, multinomial and Bernoulli distributions are popular. These assumptions lead to two distinct models, which are often confused.

Gaussian naive Bayes

When dealing with continuous data, a typical assumption is that the continuous values associated with each class are distributed according to a normal distribution. For example, suppose the training data contains a continuous attribute, . The data is first segmented by the class, and then the mean and variance of is computed in each class. Let be the mean of the values in associated with class, and let be the Bessel corrected variance of the values in associated with class. Suppose one has collected some observation value. Then, the probability density of given a class, i.e.,, can be computed by plugging into the equation for a normal distribution parameterized by and. Formally,
Another common technique for handling continuous values is to use binning to discretize the feature values and obtain a new set of Bernoulli-distributed features. Some literature suggests that this is required in order to use naive Bayes, but it is not true, as the discretization may throw away discriminative information.
Sometimes the distribution of class-conditional marginal densities is far from normal. In these cases, kernel density estimation can be used for a more realistic estimate of the marginal densities of each class. This method, which was introduced by John and Langley, can boost the accuracy of the classifier considerably.

Multinomial naive Bayes

With a multinomial event model, samples represent the frequencies with which certain events have been generated by a multinomial where is the probability that event occurs. A feature vector is then a histogram, with counting the number of times event was observed in a particular instance. This is the event model typically used for document classification, with events representing the occurrence of a word in a single document. The likelihood of observing a histogram is given by:
where.
The multinomial naive Bayes classifier becomes a linear classifier when expressed in log-space:
where and. Estimating the parameters in log space is advantageous since multiplying a large number of small values can lead to significant rounding error. Applying a log transform reduces the effect of this rounding error.
If a given class and feature value never occur together in the training data, then the frequency-based probability estimate will be zero, because the probability estimate is directly proportional to the number of occurrences of a feature's value. This is problematic because it will wipe out all information in the other probabilities when they are multiplied. Therefore, it is often desirable to incorporate a small-sample correction, called pseudocount, in all probability estimates such that no probability is ever set to be exactly zero. This way of regularizing naive Bayes is called Laplace smoothing when the pseudocount is one, and Lidstone smoothing in the general case.
Rennie et al. discuss problems with the multinomial assumption in the context of document classification and possible ways to alleviate those problems, including the use of tf–idf weights instead of raw term frequencies and document length normalization, to produce a naive Bayes classifier that is competitive with support vector machines.

Bernoulli naive Bayes

In the multivariate Bernoulli event model, features are independent Boolean variables describing inputs. Like the multinomial model, this model is popular for document classification tasks, where binary term occurrence features are used rather than term frequencies. If is a Boolean expressing the occurrence or absence of the 'th term from the vocabulary, then the likelihood of a document given a class is given by:
where is the probability of class generating the term. This event model is especially popular for classifying short texts. It has the benefit of explicitly modelling the absence of terms. Note that a naive Bayes classifier with a Bernoulli event model is not the same as a multinomial NB classifier with frequency counts truncated to one.