Professional Documents
Culture Documents
ML-Unit I - Naive Bayes
ML-Unit I - Naive Bayes
ML-Unit I - Naive Bayes
where:
● A and B are called events.
● P(A | B) is the probability of event A, given the event B is true (has occurred).
Event B is also termed as evidence.
● P(A) is the priori of A (the prior independent probability, i.e. probability of event
before evidence is seen).
● P(B | A) is the probability of B given event A, i.e. probability of event B after
evidence A is seen.
Effort (x) Result (y)
Average Pass
Average Pass
Bayes Theorem:
Good Pass
where: Good Pass
● Let’s take a one dimensional data to
Poor Fail
understand how bayes theorem
Poor Fail
works:
Poor Pass
Check “student will fail if his efforts are
poor” statement is correct or not? Poor Fail
Average Fail
Effort (x) Result (y)
Average Pass
Average Pass
where:
Good Pass
● Given problem, the bayes classifier
Good Pass
model will be:
Poor Fail
Poor Fail
Average Fail
Effort (x) Result (y)
Average Pass
Average Pass
P(Fail | Poor) = P(Poor | Fail) * P(Fail) /
P(Poor) Good Pass
Average Pass
Average Pass
P(Fail | Poor) = P(Poor | Fail) * P(Fail) /
P(Poor) Good Pass
Poor Fail
P(Pass | Poor) = P(Poor | Pass) * P(Pass) / Poor Fail
P(Poor) Poor Pass
P(Pass | Poor) = (1/6 * 6/11) /(5/11) = 0.04
Poor Fail
Average Pass
Therefore, for an new student if effort
Average Fail
given in poor, his result is fail.
Naive Bayes Exercise
Consider the training dataset are as follows:
S1 0.044
S2
S3
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (send) = 1/7= 0.14, TF * IDF (send of S1) = 0.25*0.176= 0.044
IDF (send) = log (3/2) = 0.176 TF * IDF (send of S2) = 0.14*0.176= 0.024
S1 0.044
S2 0.024
S3
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (send) = 0/6= 0, TF * IDF (send of S1) = 0.25*0.176= 0.044
IDF (send) = log (3/2) = 0.176 TF * IDF (send of S2) = 0.14*0.176= 0.024
TF * IDF (send of S3) = 0*0.176= 0
Send your mobile number account and selected as winner
S1 0.044
S2 0.024
S3 0
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (your) = 1/4= 0.25 TF * IDF (your of S1) = 0.25*0= 0
IDF (your) = log (3/3) = 0 TF * IDF (your of S2) = 0.14*0= 0
TF * IDF (your of S3) = 0.16*0= 0
Send your mobile number account and selected as winner
S1 0.044 0
S2 0.024 0
S3 0 0
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (mobile) = 1/4= 0.25 TF * IDF (mobile of S1) = 0.25*0= 0
IDF (mobile) = log (3/3) = 0 TF * IDF (mobile of S2) = 0.16*0= 0
TF * IDF (mobile of S3) = 0.14*0= 0
Send your mobile number account and selected as winner
S1 0.044 0 0
S2 0.024 0 0
S3 0 0 0
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (account) = 0/4= 0 TF * IDF (account of S1) = 0*0.477= 0
IDF (account) = log (3/1) = 0.477 TF * IDF (account of S2) = 0.16*0.477= 0.119
TF * IDF (account of S3) = 0*0= 0
Send your mobile number account and selected as winner
S1 0.044 0 0 0 0
S2 0.024 0 0 0 0.076
S3 0 0 0 0 0
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (selected) = 0/4= 0 TF * IDF (selected of S1) = 0*0.477= 0
IDF (selected) = log (3/1) = 0.477 TF * IDF (selected of S2) = 0*0.477= 0
TF * IDF (selected of S3) = 0.14*0.477= 0.076
Send your mobile number account and selected as win
ner
S1 0.044 0 0 0 0 0 0
S3 0 0 0 0 0 0 0.076
SMS spam classification:
Feature extraction
Step 2: Calculate the TF-IDF feature
TF (winner) = 0/4= 0 TF * IDF (winner of S1) = 0*0.477= 0
IDF (winner) = log (3/1) = 0.477 TF * IDF (winner of S2) = 0*0.477= 0
TF * IDF (winner of S3) = 0.14*0.477= 0.076
Send your mobile number account and selected as winner
S1 0.044 0 0 0 0 0 0 0 0
S1 0.044 0 0 0 0 0 0 0 0 Ham
S1 0.044 0 0 0 0 0 0 0 0 Ham
S1 0.044 0 0 0 0 0 0 0 0 Ham
S1 0.044 0 0 0 0 0 0 0 0 Ham