Day 26 of 100DaysofML

Charan Soneji
100DaysofMLcode
Published in
4 min readJul 12, 2020

Naive Bayes. One of the most commonly used algorithms whose formula is very commonly used in a lot of the problems that we solve in probability and is given by Bayesian probability. So what exactly is Naive Bayes. Lets start with the formal definition:

In statistics, Naïve Bayes classifiers are a family of simple “probabilistic classifiers” based on applying Bayes’ theorem with strong independence assumptions between the features.

So the entire concept of Naive Bayes revolves around the bayesian formula. So let us give a look at that formula. Keep in mind that understanding conditional probability is essential for this given task.

Bayesian formula

The formula states that the probability of an event A given that B is occurring is given by the formula: Probability of B given that A occurs over the entire probability of B. The formula might seem a little overwhelming but understanding a few concepts sorts the problem.

I won't be able to cover much in this blog (time constraints) but I shall cover the essentials and provide the resources that I used to study this topic.

Some of the key things that we need to know are that bayesian classifiers are statistical classifiers that can predict the class membership probabilities such as the probability of whether a given tuple belongs to a class or not. For example: Is it going to rain today or Am i going to win the cricket match. So in this manner, Naive bayes takes in the overall features and calculates the conditional probability of the event happening versus the event not happening and then consolidates all the probabilities in order to make a prediction.

Another thing to keep in mind is that Naive Bayes makes use of prior probability of each category given no information about an item. Let us take a look at the example given below:

Naive Bayes example

So this is one of the examples everyone starts off with while they learn Naive bayes and my faculty in Data Mining had introduced this problem to me. So let us try to understand the approach towards solving this question.

We classify whether the day is suitable for playing tennis, given the features of the day. The columns represent these features and the rows represent individual entries. If we take the first row of the dataset, we can observe that is not suitable for playing tennis if the outlook is rainy, temperature is hot, humidity is high and it is not windy. We make two assumptions here, one as stated above we consider that these predictors are independent. That is, if the temperature is hot, it does not necessarily mean that the humidity is high. Another assumption made here is that all the predictors have an equal effect on the outcome. That is, the day being windy does not have more importance in deciding to play tennis or not.

So based on the probabilities of each of the given columns in the table, we generate or create more refined tables and probabilities, which look a little something like this:

Example table

Im going to quickly try to summarize the approach along with the question asked, make sure to watch the video given below, if you found the explanation confusing.

Question

The above given is a question which is usually asked whereby we would be asked to classify based on a given set of conditions (X) as given in the question. The calculations done is shown in the diagram below which simply involves multiplying the probabilities which you have obtained from the tables above.

Naive Bayes solution for above given question

Please make sure to watch the video given below if y’all have any confusion.

That’s it for today. Keep Learning.

Cheers.

--

--