Jump to content

Naive Bayes classifier: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Karipuf (talk | contribs)
→‎Discussion: Stated the curse of dimensionality as one of the reasons why the Naive Bayesian Classifier works surprisingly well. Some minor re-arrangements.
→‎Example: document classification: added clarification "In other words, what is P(C|D)?" since I was confused myself when I read the original formulation
Line 85: Line 85:
:<math>p(D\vert C)=\prod_i p(w_i \vert C)\,</math>
:<math>p(D\vert C)=\prod_i p(w_i \vert C)\,</math>


The question that we desire to answer is: "what is the probability that a given document ''D'' belongs to a given class ''C''?"
The question that we desire to answer is: "what is the probability that a given document ''D'' belongs to a given class ''C''?" In other words, what is <math>p(C \vert D)\,</math>?


Now, by their definition, (see [[Probability axiom]])
Now, by their definition, (see [[Probability axiom]])

Revision as of 22:00, 20 September 2006

A naive Bayes classifier (also known as Idiot's Bayes) is a simple probabilistic classifier based on applying Bayes' theorem with strong (naive) independence assumptions. A more descriptive term for the underlying probability model would be independent feature model.

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. 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.

The naive Bayes probabilistic model

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

over a dependent class variable with a small number of outcomes or classes, conditional on several feature variables through . The problem is that if the number of features 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

In practice we are only interested in the numerator of that fraction, since 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 repeated applications of the definition of conditional probability:

and so forth. Now the "naive" conditional independence assumptions come into play: assume that each feature is conditionally independent of every other feature for . This means that

and so the joint model can be expressed as

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

where is a scaling factor dependent only on , 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 and independent probability distributions . If there are classes and if a model for can be expressed in terms of parameters, then the corresponding naive Bayes model has (k − 1) + n r k parameters. In practice, often (binary classification) and (Bernoulli variables as features) are common, and so the total number of parameters of the naive Bayes model is , where 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 defined as follows:

Empty (or sparse) attributes

When constructing a classifier using Bayes' rule of conditional probability, one should take care when the training set contains empty or sparse attributes, e.g. when one of the values may be unknown. When these values are represented using 0 (zero) values and are in turn used in the multiplication, the outcome of will be also 0. In other words, empty attribute values hold a veto over the other attributes in the set.

This problem may be cured by adding a small number to each attribute value, which is a process called Laplace smoothing.

Discussion

Despite the fact that the far-reaching independence assumptions are often inaccurate, the naive Bayes classifier has several properties that make it surprisingly useful in practice. In particular, the decoupling of the class conditional feature distributions means that each distribution can be independently estimated as a one dimensional distribution. This in turn helps to alleviate problems stemming from the curse of dimensionality, such as the need for data sets that scale exponentially with the number of features. 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; hence 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-mails. 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

(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

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

Now, by their definition, (see Probability axiom)

and

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

Assume for the moment that there are only two classes, S and ¬S (e.g. spam and not spam).

and

Using the Bayesian result above, we can write:

Dividing one by the other gives:

Which can be re-factored as:

Thus, the probability ratio p(S | D) / p(¬S | D) can be expressed in terms of a series of likelihood ratios. The actual probability p(S | D) can be easily computed from log (p(S | D) / p(¬S | D)) based on the observation that p(S | D) + p(¬S | D) = 1.

Taking the logarithm of all these ratios, we have:

(This technique of "log-likelihood ratios" is a common technique in statistics. In the case of two mutually exclusive alternatives (such as this example), the conversion of a log-likelihood ratio to a probability takes the form of a sigmoid curve: see logit for details.)

Finally, the document can be classified as follows. It is spam if , otherwise it is not spam.

See also

References

  • Domingos, Pedro & Michael Pazzani (1997) "On the optimality of the simple Bayesian classifier under zero-one loss". Machine Learning, 29:103–­137. (also online at CiteSeer: [1])
  • Rish, Irina. (2001). "An empirical study of the naive Bayes classifier". IJCAI 2001 Workshop on Empirical Methods in Artificial Intelligence. (available online: PDF, PostScript)
  • Hand, DJ, & Yu, K. (2001). "Idiot's Bayes - not so stupid after all?" International Statistical Review. Vol 69 part 3, pages 385-399. ISSN 0306 7734.
  • Mozina M, Demsar J, Kattan M, & Zupan B. (2004). "Nomograms for Visualization of Naive Bayesian Classifier". In Proc. of PKDD-2004, pages 337-348. (available online: PDF)
  • Maron, M. E. (1961). "Automatic Indexing: An Experimental Inquiry." Journal of the ACM (JACM) 8(3):404–417. (available online: PDF)
  • McCallum, A. and Nigam K. "A Comparison of Event Models for Naive Bayes Text Classification". In AAAI/ICML-98 Workshop on Learning for Text Categorization, pp. 41-48. Technical Report WS-98-05. AAAI Press. 1998. (available online: PDF).

External links

Software