scikits.learn.naive_bayes
Naive Bayes algorithms are a set of supervised learning methods based on applying Bayes' theorem with the "naive" assumption of independence between every pair of features. Given a class variable c and a dependent set of feature variables f1 through fn, Bayes' theorem states the following relationship:
p(c ∣ f1, …, fn) ∝ p(c)p( ∣ f1, …, fn ∣ c)
Using the naive assumption this relationship is simplified:
where we used the Maximum a Posteriori estimator.
The different naive Bayes classifiers differ by the assumption on the distribution of p(fi ∣ c):
In spite of their naive design and apparently over-simplified assumptions, naive Bayes classifiers have worked quite well in many real-world situations, famously document classification and spam filtering. They requires a small amount of training data to estimate the necessary parameters.
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.
GaussianNB
implements the Gaussian Naive Bayes algorithm for classification. The likelihood of the features is assumed to be gaussian:
The parameters of the distribution, σc and μc are estimated using maximum likelihood.
Examples:
example_naive_bayes.py
,
MultinomialNB
implements the Multinomial Naive Bayes algorithm for classification. Multinomial Naive Bayes models the distribution of words in a document as a multinomial. The distribution is parametrized by the vector
where fi is the frequency count of word i. It can be shown that the maximum posterior probability is,
The vector of parameters
where Nci is the number of times word i appears in a document of class c and Nc is the total count of words in a document of class c. The smoothness priors αi and their sum α account for words not seen in the learning samples.