Naive Bayes Theorem and Application


Naive Bayes Theorm And Application - Theorem

Naive Bayes model:
1. Naive Bayes model
2. model: discrete attributes with finit number of values
2. Parameter density estimation
3. Naive Bayes classification algorithm
4. AutoClass clustering alogrithm

( extbf{1. Naive Bayes model})
In this model, We want to estimate (P(X_1,...,X_n)), While the assumption is that all attributes independent of each other, this is the same assumption as k-means, except this is discrete model.$$P(X_1,...,X_n)=Pi(X_1,...,P_n)$$While (P(X_i)) can be any distribution you like, e.g. ({0.5 : red, 0.2 : blue, 0.3 : yellow}).
To simplify this problem, we assume all attributes Boolean. With no independence assumptions , the model will have (2_n) states of (X_1,...,X_n) and (2^n-1) independent parameters; While adding independence assumption, the the scale of parameters decreases to (2n+1), and the parameter and n parameters in total.
For example,in a classification problem,We assume ( heta_C) is the probability class. Then we have 2n+1 parameters:

[egin{align} &P(C=T)= heta_C otag\ &P(C=T)=1 - heta_C otag\ &P(X_i=T|C=T)= heta_{i}^T otag\ &P(X_i=F|C=T)=1 - heta_{i}^T otag\ &P(X_i=F|C=T)=1 - heta_{i}^F otag\ & mathbf{ heta}langle { heta_C, heta_{i}^T,..., heta_{n}^T, heta_{i}^F,... heta_{n}^F} angle otag\ end{align}]

As you can see above, it makes incredible saving in number of parameters. Representing (P(X_1,.., X_n)) explicitly suffers from curse of dimensionality, while (Pi_{i=1}^n P(X_i)) does not. This savings results from very strong independence assumptions. In fact, Naive Bayes model performs very well when assumptions hold, but perform very bad when varibables are dependent. For example, NB model performs well in English but badly in Chinese for context are more imporant for understanding chinese correctrly. So we should be cautious about applying this strong assumptions to those model whose parameters are in substantially related.

Naive Bayes classifier
For a NB classification problem we should learn:
1. (P(X_1,...X_n|C)=Pi_{i=1}^nP(X_i|C)), for each class assumes that (X_i) and (X_j) are conditionally independent of each other given C.
2. P(C)
To classify: given (f{x}), choose c that maximizes:

[P(c|x)~propto~P(c)P(x_i|c) ]

The NB classifier is a linear separators. Attributes act independently to produce classification, and they not interact, therefore they cannot capture concepts like XOR just like preceptrons.
There is an important point about linear separable problem. Many real world domains are not linearly separable, even for those domains there may be a pretty good linearly separable hypothesis. We may be better off learning a linearly separable hypothesis than learning a richer htpothesis. This is from a strong inductive bias - ( extbf{eaiser to learn}).

In the following discussion we will assume that attributes and class are Boolean, and this is only to keep the notation simple. Everything generalizes to the case have many possible values.

A simple problem:
There is a soccer team, we have observed a sequence of games of the team. Based on this, we want to estimate the probability that the team will win a future game. The formulation about the problem is below:
* Variable X has states {f, t}(t = win)
* Parameter ( heta=P(X=t))
* Observations (X^1=t, X^2=f, X^3=f)
* These comprise the data (f{D})
* Task: estimate ( heta)
* Use ( heta) to estimate (P(X^4=t))
Firstly we will introduce ( extbf{Maximum likelihood(ML)}) algorithm, the likelihood mean:
* ( extbf{Likelihhod:}) (f{L}( heta)=P(f{D}| heta)=P(X^1,X^2,X^3| heta))
* ( extbf{ML Principle:}) Choose ( heta) so as to maximize(mathbf{L}( heta))
* (L( heta)=P(X^1| heta)P(X^2| heta)P(X^3| heta))
* ( extbf{Log likelihood:}) $$f{LL}( heta)=logP(X1| heta)+logP(X2| heta)+logP(X^3| heta)$$
* ML Principle equivalent: Choose ( heta) so as to maximize (LL( heta))
In this example:
(P(X^i=t| heta)= heta)
(L( heta)=P(X^1=t, X62=f, X^3=f| heta)= heta(1- heta)(1- heta))
(LL( heta)=log heta+2log(1- heta))
set derivative to 0: (frac{1}{ heta}~-~frac{2}{1- heta} = 0)
Solve to find: ( heta=1/3)
In the example just now, you can find that ( heta=1/3) exactly the fraction of observed games in which the team won. But this is no coincidence: The ML estimate for the probability of an event always the fraction of time in which the event happened.In other words, ML's estimate is exactly the one most suggested by the data. More generally, we get the observations (X^1,X^2,...,X^n), let (N_t) be the number of instances with value t and (N_f) be the number of instances with value f. Then the maximum likelihood estimate for ( heta) is: $$hat{ heta}=frac{N_t}{N_t+N_f}=frac{N_t}{N}$$
( extbf{Problem with this approach})
(color{red}{Overfits}:) pays too much attention to noise in the data, for example if the team was particularly compete with (color{red}{ extbf{Chinese national soccer team}}) recently, then we will oversee the team performance.
(color{red}{Ignores\,prior\,experience}): If some experts told you that the team is a small team, you should not be confident even you have won CNS.
Events don't occur in the data are deemed impossible, for example the match end with 1 vs 1.

( extbf{Incorporating a prior})
* ( extbf{Prior}:) (P( heta)) before seeing any data
* ( extbf{Posterior:}) (P( heta|mathbf{D}))
* ( extbf{Maximum a Posterior principle (MAP):}) Choose ( heta) to maximize (P( heta|mathbf{D})) and (P( heta|mathbf{D})) is proportional to (P( heta)L( heta))
For learning the parameter of a Boolean random variable, an appropriate prior over ( heta) is the ( extbf{beta}) distribution. As you know, the beta distribution has 2 ( extbf{parameters:}) (alpha) and (eta), and these paramters control the shape of the prior. (alpha) and (eta) control how relatively likely true and false outcomes are, if (alpha) is large relative to (eta), ( heta) will be more likely to be large.
As the graph below:

And the (color{red}{magnitude}) of (alpha) and (eta) control how peaked the beta distribution is, if (alpha) and (eta) are large, the beta will be sharply peaked.
The magnitude of (alpha) and (eta):

Updating the prior
To get the hyperparameters for the posterior, we take the haperparamaters in the prior, and add to them the actual abservations that we get:
for example, the prior is Beta(4, 7), and we observe 1 "+"" and 4 "-", then the posterior is Beta(5, 11).

Understanding the hyperparameters
Hyperparameter (alpha) represents the number of previous positive observation that we had, plus 1; similarly, (eta) represents the number of previous "-" observations that we have had, plus 1. Hyperparameters in the prior as represent imaginary observations in our prior exprerience. ( extbf{The more we trust our prior experience, the larger the hyperparameters in the prior.})

Mode and mean of the beta distribution
The mode of (Beta(alpha,eta)) is (frac{alpha-1}{alpha-eta-2}). e.g. mode of Beta(2,3) is 1/3. The mean of (Beta(alpha,eta)) is (frac{alpha}{alpha+eta}). e.g. mean of Beta(2,3) is 2/5.

MAP estimate
For the picture just now, we can see the MAP estimate is the mode of the posterior. This is the fraction of the total number of the observations that are true. e.g. for m postive instances out of N total $$hat{ heta_{MAP}}=frac{m+alpha-1}{N+alpha+eta-2}$$

In the example above, the prior is Beta(5,3), and the observations is: (X^1=t, X^2=f,X^3=f), so the posterior is: Beta(6,5), The MAP estimate is: $$hat{ heta_{MAP}}=frac{m+alpha-1}{N+alpha+eta-2}=frac{5}{9}$$
ML vs MAP
Maximum likelihood estimate: (hat{ heta_{ML}}=frac{m}{N}); MAP estimate: (hat{ heta_{MAP}}=frac{m+alpha-1}{N+alpha+eta-2}). And Maximum likelihood is equivalent to MAP with a uniform prior: Beta(1,1), meaing that there are no imaginary observations.
Drawback of MAP
MAP not fully consider the range of possible values for ( heta), only choose the maximum value, this value may not be representative.(With greatest probability) So we introduce another approach, ( extbf{Baysian approach}), this approach not makeestimate of ( heta). and the posterior distribution is maintainted over the value of ( heta). e.g. given (X^1,X^2,X^3) we want to predict (X^4) using the entire distribution over ( heta).

[egin{align} P(X^4|X^1,X^2,X^3)&=int_{0}^1{P(X^4| heta)P( heta|X^1,X^2,X^3)}d heta otag\ & = int_{0}^1 heta{P( heta|X^1,X^2,X^3)}d heta otag\ & = Eleft[ { heta |X^1, X^2, X^3} ight] otag\ & = mathbf{mean}\,of\,the\,posterior otag\ end{align}]

For beta distribution (Eleft[{ heta=frac{m+alpha}{N+alpha+eta}} ight])
(Eleft[{ heta} ight]) is the estimate of the probability that a new instance is true. And this is obtained by integrating over the posterior distribution.
In the problem above, with prior Beta(5, 3), the Maximum posrterior probability is (hat{ heta_{MAP}}=frac{m+alpha-1}{N+alpha+eta-2}=frac{5}{9}), while the Bayesian approach Expectation is: (hat{ heta_{MAP}}=frac{m+alpha}{N+alpha+eta}=frac{6}{11}), we can see the latter is more closely to 1/2.

( extbf{Multi-valued class and attributes})
In the first part of this essay, we only simplify the attributes and class to boolean, now generalizes to multi-value class and attributes.
given that: |C| = k and |X|=m, and parameters are listed as below:

[egin{align} &P(C=c)= heta_c otag\ &P(X_i=x|C=c)= heta_{i,x}^c otag\ end{align}]

So the parameters grows up to kmn+k-1, the counts of instances is also listed below:

[egin{align} &- N=total\,number\,of\,instances otag\ &- N=total\,number\,of\,instances\,with\,class\,c otag\ &- N=total\,number\,of\,instances\,with\,class\,c\,and\,X_i=x otag\ &- k*m*n+k+1\,parameters\,in\,total. otag\ end{align}]

From the analysis above, we can make a brief conclusion about Naive Bayes:
The advantages is that BN not suffers from the curse of dimensionality, and as you can see it very easy to implement, and it learns fastly. In each dimension, it makes no assumption about form of distribution. While in the other perspective, Naive Bayes make a strong independence assumption, it may perform poorly if this not hold(Chinese for example), and finding Maximum likelihood can overfit data.
( extbf{reference})
Note: Most content of this essay are from CMU lecture, while I lose the link of the website.
CMU statistical learning

原文地址:https://www.cnblogs.com/wenwangt/p/5364179.html