Data Science me!

The math behind naïve Bayes

This is the likelihood any given customer will purchase without considering other variables. In our data set, 50% of customers purchase.

Probabilities Calculated

The formula that Naïve Bayes relies on is shown to the right. Simply stated, in our data set, we know the overall likelihood that a random customer will make a purchase is 50% as, half of the customers in the data set made a purchase and half of the customers did not.

We also know that within the 10 customers that made a purchase, 6 were women and 4 were men and out of the 10 customers that did not make a purchase, 3 were women and 7 were men. From just that information, we can conclude that if our customer is a woman, the 50% likelihood of making a purchase should be adjusted upward, and the likelihood that the customer will not make a purchase should be adjusted downward.

Naïve Bayes is a relative likelihood model, so, we compare the adjusted likelihood of the customer making a purchase with the adjusted likelihood of the customer not making a purchase and that will identify the customers we expect to make a purchase.  

In the file listed below, is a table that calculates all of the individual probabilities, an image of which is shown below. 

The file below demonstrates how a naive bayes model works on a simple data set

Let's start with the name. Bayes refers to Thomas, an 18th century English statistician known for developing Bayes' Theorem, upon which the Naïve Bayes model is built. So, why was he naïve? Well actually Bayes was not naive, but the naïveté in this model comes from variables that are assumed to be independent. In the data set used, there are only four variables, Age, Education, Income and Gender that will be used to predict if someone will make a purchase.

In reality we can assume that age and education will both have an impact on income, that is, as one gets older, their average income will rise and as one obtains more education their income will also rise. Additionally, as one gets older, the amount of education they have received will likely rise. These variables therefore are definitely not independent. With a Naïve Bayes model though, we are going to treat them as if they are, that is what makes the model "naïve".     

These are the likelihood of a purchase when considering each variable independently, and the result of each of these is multiplied together. 

Naïve Bayes...Don't be so Naïve!

The probability of purchase or no purchase by each variable independently.

The probability within the customers that purchased and didn't purchase.