Naive Bayes Classifier

author: daodeiv (David Stankov) daodavid

Naive Bayes is one of the simplest supervised ML algorithms meanwhile very efficient and also is able to learn fast and make a quick prediction, therefore it is so useful and popular. Naive Bayes contains two words Naive and Bayes, Bayes because it is built on Bayes Theorem, and Naive because it assumes that features are independent even if they actually are interdependent.It is simple but very powerful and works well with large datasets and sparse matrices. It works really well on text classification problems, and spam filtering.

Bayes Theorem

Bayes theorem describes a probability of an event, based on prior knowledge of conditions that might be related to an event. First, let's take the formula of conditional probability and try to derive Bayes Theorem:

$$p(A|B) = \frac{p(B\cap A)}{p(B)}$$

Probability of event A given B, meaning what is the probability of A when event B is already taken place, which is equal to the probability of A intersection B (the probability of both A and B events are taking place) divided by the probability of B.

we have the same for probability of event B given event A $$p(B|A) = \frac{p(A\cap B)}{p(A)}$$ the $p(A\cap B)$ and $p(B\cap A)$ are basicaly the same. Since they are the same, we can get two formulas and move denominator to the left of the equation,and equate them $$ p(B|A)p(A) = p(A\cap B) = p(B \cap A) = p(A|B)p(B) $$

So, when we want to find probability of A given B we can write our equation on this way:

$$P(A|B) = \frac{ P(B|A) * P(A)}{ P(B)}$$,

and this is the equation of Bayes Theorem

How does Binomial Naive Bayes work? (implementation)

For our purposes we are going to use Golf Play Dataset

References