LM39 - Naïve Bayes Models
LM39 - Naïve Bayes Models
LM39 - Naïve Bayes Models
The Naïve Bayes algorithm is comprised of two words Naïve and Bayes, Which can be described
as:
Naïve: It is called Naïve because it assumes that the occurrence of a certain feature is
independent of the occurrence of other features. Such as if the fruit is identified on the bases of
color, shape, and taste, then red, spherical, and sweet fruit is recognized as an apple. Hence each
feature individually contributes to identify that it is an apple without depending on each other.
•Naïve Bayes algorithm is a supervised learning algorithm, which is based on Bayes theorem and
•It is mainly used in text classification that includes a high-dimensional training dataset.
•Naïve Bayes Classifier is one of the simple and most effective Classification algorithms which helps
in building the fast machine learning models that can make quick predictions.
•It is a probabilistic classifier, which means it predicts on the basis of the probability of an object.
•Some popular examples of Naïve Bayes Algorithm are spam filtration, Sentimental analysis, and
•Bayes' theorem is also known as Bayes' Rule or Bayes' law, which is used to determine the
Where,
P(A|B) is Posterior probability: Probability of hypothesis A on the observed event B.
P(B|A) is Likelihood probability: Probability of the evidence given that the probability of a hypothesis is true.
P(A) is Prior Probability: Probability of hypothesis before observing the evidence.
P(B) is Marginal Probability: Probability of Evidence.
AL3391/AI/II AI&DS/III SEM/KG-KiTE
NAÏVE BAYES MODELS
Working of Naïve Bayes' Classifier: (can be understood with the help of the below example):
•Suppose we have a dataset of weather conditions and corresponding target variable "Play". So using
this dataset we need to decide that whether we should play or not on a particular day according to the
weather conditions.
Problem: If the weather is sunny, then the Player should play or not?
Solution: To solve this, first consider the below dataset:
Outlook Play
0 Rainy Yes
1 Sunny Yes
2 Overcast Yes
3 Overcast Yes
4 Sunny No
5 Rainy Yes
6 Sunny Yes
7 Overcast Yes
8 Rainy No
9 Sunny No
10 Sunny Yes
11 Rainy No
12 Overcast Yes
13 AL3391/AI/II
Overcast AI&DS/III SEM/KG-KiTE
Yes
NAÏVE BAYES MODELS
Frequency table for the Weather Conditions: Likelihood table weather condition:
Applying Bayes'theorem:
P(Yes|Sunny)= P(Sunny|Yes)*P(Yes)/P(Sunny)
P(Sunny)= 0.35
P(Yes)=0.71
Applying Bayes'theorem:..
P(No|Sunny)= P(Sunny|No)*P(No)/P(Sunny)
P(Sunny|NO)= 2/4=0.5
P(No)= 0.29
P(Sunny)= 0.35
So that P(Yes|Sunny)>P(No|Sunny)
AL3391/AI/II AI&DS/III SEM/KG-KiTE
Hence on a Sunny day, Player can play the game.
NAÏVE BAYES MODELS
•Naïve Bayes is one of the fast and easy ML algorithms to predict a class of datasets.
•Naive Bayes assumes that all features are independent or unrelated, so it cannot learn the relationship
•It can be used in real-time predictions because Naïve Bayes Classifier is an eager learner.
•It is used in Text classification such as Spam filtering and Sentiment analysis.