Naive Bayes Classifier Article Index for
Naive
Shopping
Bayes
 

Information About

Naive Bayes Classifier




Depending on the precise nature of the probability model, naive Bayes classifiers can be trained very efficiently in a Supervised Learning setting. 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 believing in Bayesian Probability or using any Bayesian methods.

In spite of their naive design and apparently over-simplified assumptions, naive Bayes classifiers often work much better in many complex real-world situations than might be expected from their very simple design. Recently, careful analysis of the Bayesian classification problem has shown that there are sound theoretical reasons for the apparently unreasonable efficacy of naive Bayes classifiers (see references at the end of this article for more details).


THE NAIVE BAYES PROBABILISTIC MODEL


Abstractly, the probability model for a classifier is a conditional model

:p(C ert F_1,\dots,F_n)\,

over a dependent class variable C with a small number of outcomes or ''classes'', conditional on several feature variables F_1 through F_n. The problem is that if the number of features n is large or when a feature can take on a large number of values, then basing such a model on probability tables is infeasible. We therefore reformulate the model to make it more tractable.

Using Bayes' Theorem , we write

:p(C ert F_1,\dots,F_n) = rac{p(C) \ p(F_1,\dots,F_n ert C)}{p(F_1,\dots,F_n)}. \,

In practice we are only interested in the numerator of that fraction, since the denominator does not depend on C and the values of the features F_i are given, so that the denominator is effectively constant.
The numerator is equivalent to the Joint Probability model

:p(C, F_1, \dots, F_n)\,

which can be rewritten as follows, using repeated applications of the definition of Conditional Probability :

:p(C, F_1, \dots, F_n)\,

::= p(C) \ p(F_1,\dots,F_n ert C)

::= p(C) \ p(F_1 ert C) \ p(F_2,\dots,F_n ert C, F_1)

::= p(C) \ p(F_1 ert C) \ p(F_2 ert C, F_1) \ p(F_3,\dots,F_n ert C, F_1, F_2)

::= p(C) \ p(F_1 ert C) \ p(F_2 ert C, F_1) \ p(F_3 ert C, F_1, F_2) \ p(F_4,\dots,F_n ert C, F_1, F_2, F_3)

and so forth. Now the "naive" of every other feature F_j for j
eq i. This means that

:p(F_i ert C, F_j) = p(F_i ert C)\,

and so the joint model can be expressed as

:p(C, F_1, \dots, F_n)
= p(C) \ p(F_1 ert C) \ p(F_2 ert C) \ p(F_3 ert C) \ \cdots\,

:= p(C) \prod_{i=1}^n p(F_i ert C).\,

This means that under the above independence assumptions, the conditional distribution over the class variable C can be expressed like this:

:p(C ert F_1,\dots,F_n) = rac{1}{Z} p(C) \prod_{i=1}^n p(F_i ert C)

where Z is a scaling factor dependent only on F_1,\dots,F_n, i.e., a constant if the values of the feature variables are known.

Models of this form are much more manageable, since they factor into a so-called ''class prior'' p(C) and independent probability distributions p(F_i ert C). If there are k classes and if a model for p(F_i) can be expressed in terms of r parameters, then the corresponding naive Bayes model has (''k'' − 1) + ''n'' ''r'' ''k'' parameters. In practice, often k=2 (binary classification) and r=1 ( Bernoulli Variable s as features) are common, and so the total number of parameters of the naive Bayes model is 2n+1, where n is the number of binary features used for prediction.


PARAMETER ESTIMATION


In a Supervised Learning setting, one wants to estimate the parameters of the probability model. Because of the independent feature assumption, it suffices to estimate the class prior and the conditional feature models independently, using the method of Maximum Likelihood , Bayesian Inference or other parameter estimation procedures.


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; this is known as the '' Maximum A Posteriori '' or ''MAP'' decision rule. The corresponding classifier is the function \mathrm{classify} defined as follows:

:\mathrm{classify}(f_1,\dots,f_n) = \mathop{\mathrm{argmax}}_c \ p(C=c) \prod_{i=1}^n p(F_i=f_i ert C=c)


DISCUSSION


The naive Bayes classifier has several properties that make it surprisingly useful in practice, despite the fact that the far-reaching independence assumptions are often violated. Like all probabilistic classifiers under the MAP decision rule, it arrives at the correct classification as long as the correct class is more probable than any other class; class probabilities do not have to be estimated very well. In other words, the overall classifier is robust enough to ignore serious deficiencies in its underlying naive probability model. Other reasons for the observed success of the naive Bayes classifier are discussed in the literature cited below.


EXAMPLE: DOCUMENT CLASSIFICATION


Here is a worked example of naive Bayesian classification to the Document Classification problem.
Consider the problem of classifying documents by their content, for example into Spam and non-spam E-mail s. Imagine that documents are drawn from a number of classes of documents which can be modelled as sets of words where the (independent) probability that the i-th word of a given document occurs in a document from class ''C'' can be written as

:p(w_i ert C)\,

(For this treatment, we simplify things further by assuming that the probability of a word in a document is independent of the length of a document, or that all documents are of the same length.)

Then the probability of a given document ''D'', given a class ''C'', is

:p(D ert C)=\prod_i p(w_i ert C)\,

The question that we desire to answer is: "what is the probability that a given document ''D'' belongs to a given class ''C''?"

Now, by their definition, (see Probability Axiom )

:p(D ert C)={p(D\cap C)\over p(C)}

and

:p(C ert D)={p(D\cap C)\over p(D)}

Bayes' theorem manipulates these into a statement of probability in terms of Likelihood .

:p(C ert D)={p(C)\over p(D)}\,p(D ert C)

Assume for the moment that there are only two classes, ''S'' and ¬''S''.

:p(D ert S)=\prod_i p(w_i ert S)\,

and

:p(D ert
eg S)=\prod_i p(w_i ert
eg S)\,

Using the Bayesian result above, we can write:

:p(S ert D)={p(S)\over p(D)}\,\prod_i p(w_i ert S)

:p(
eg S ert D)={p(
eg S)\over p(D)}\,\prod_i p(w_i ert
eg S)

Dividing one by the other gives:

:{p(S ert D)\over p(
eg S ert D)}={p(S)\,\prod_i p(w_i ert S)\over p(
eg S)\,\prod_i p(w_i ert
eg S)}

Which can be re-factored as:

:{p(S)\over p(
eg S)}\,\prod_i {p(w_i ert S)\over p(w_i ert
eg S)}

  The Actual Probability P(''S'' ''D'') Can Be Easily Computed From Log (p(''S'' ''D'') / P(&not''S'' ''D'')) Based On The Observation That P(''S'' ''D'') + P(&not''S'' ''D'') 1