Class 4 Naive Bayes Classification 2
Class 4 Naive Bayes Classification 2
The Bayes in Naïve Bayes comes from Bayes’ Theorem. If you paid attention to
probability and statistics in your maths class, there’s little chance you haven’t already
heard of Bayes’ theorem. Let’s recall it:
Bayes’ Theorem describes the probability of an event based on prior knowledge of the
conditions that might be related to the event.
This equation is derived from the formula of conditional probability given below:
Let’s take a silly little example – Say the likelihood of a person having Arthritis if they are
over 65 years of age is 49%.
Class Prior: The probability of a person stepping in the clinic being >65-year-old is 20%
Predictor Prior: The probability of a person stepping into the clinic having Arthritis is
35%
What is the probability that a person is >65 years given that he has Arthritis? This is Let’s
calculate this with the help of Bayes’ theorem!
In fact, Bayes’ Theorem is nothing but an alternate way of calculating the conditional
probability of an event. When the reverse conditional probability is easier to calculate
than the joint probability, Bayes’ Theorem is used.
You can use Bayes’ theorem to build a learner ML model, from an existing set of
attributes, that predicts the probability of the response variable belonging to some class,
given a new set of attributes.
Consider the previous equation again. Now, assume that event A is the response variable
and event B is the input attribute. So according to the equation,
Next, you need to create a frequency table for each attribute of your dataset.
Let’s say you want to focus on the likelihood that you go for a run given that it’s sunny
outside.
P(Yes|Sunny) = P(Sunny|Yes) * P(Yes) / P(Sunny) = 0.625 * 0.571 / 0.428 = 0.834
This helps in simplifying the calculations by dropping the denominator from the formula
while assuming independence:
Say you want to predict if on the coming Wednesday, given the following weather
conditions, should you go for a run or sleep in:
Outlook: Rainy
Humidity: Normal
Wind: Weak
Run: ?
Now, to determine the probability of going for a run on Wednesday, you just need to
divide P(Yes) with the sum of the likelihoods of Yes and No.
According to the model, it looks like there’s an almost 83% probability that you’re going
to stay under the covers next Wednesday!