SlideShare a Scribd company logo
Naive Bayes Classifier
Bayesian Methods
 Our focus this lecture
 Learning and classification methods based on
probability theory.
 Bayes theorem plays a critical role in probabilistic
learning and classification.
 Uses prior probability of each category given no
information about an item.
 Categorization produces a posterior probability
distribution over the possible categories given a
description of an item.
Basic Probability Formulas
 Product rule
 Sum rule
 Bayes theorem
 Theorem of total probability, if event Ai is
mutually exclusive and probability sum to 1
)
(
)
|
(
)
(
)
|
(
)
( A
P
A
B
P
B
P
B
A
P
B
A
P 


)
(
)
(
)
(
)
( B
A
P
B
P
A
P
B
A
P 







n
i
i
i A
P
A
B
P
B
P
1
)
(
)
|
(
)
(
)
(
)
(
)
|
(
)
|
(
D
P
h
P
h
D
P
D
h
P 
Bayes Theorem
 Given a hypothesis h and data D which bears on the
hypothesis:
 P(h): independent probability of h: prior probability
 P(D): independent probability of D
 P(D|h): conditional probability of D given h:
likelihood
 P(h|D): conditional probability of h given D: posterior
probability
)
(
)
(
)
|
(
)
|
(
D
P
h
P
h
D
P
D
h
P 
Does patient have cancer or not?
 A patient takes a lab test and the result comes back positive.
It is known that the test returns a correct positive result in
only 99% of the cases and a correct negative result in only
95% of the cases. Furthermore, only 0.03 of the entire
population has this disease.
1. What is the probability that this patient has cancer?
2. What is the probability that he does not have cancer?
3. What is the diagnosis?
Maximum A Posterior
 Based on Bayes Theorem, we can compute the
Maximum A Posterior (MAP) hypothesis for the data
 We are interested in the best hypothesis for some
space H given observed training data D.
)
|
(
argmax D
h
P
h
H
h
MAP


)
(
)
(
)
|
(
argmax
D
P
h
P
h
D
P
H
h

)
(
)
|
(
argmax h
P
h
D
P
H
h

H: set of all hypothesis.
Note that we can drop P(D) as the probability of the data is constant
(and independent of the hypothesis).
Maximum Likelihood
 Now assume that all hypotheses are equally
probable a priori, i.e., P(hi ) = P(hj ) for all hi,
hj belong to H.
 This is called assuming a uniform prior. It
simplifies computing the posterior:
 This hypothesis is called the maximum
likelihood hypothesis.
)
|
(
max
arg h
D
P
h
H
h
ML


Desirable Properties of Bayes Classifier
 Incrementality: with each training example,
the prior and the likelihood can be updated
dynamically: flexible and robust to errors.
 Combines prior knowledge and observed
data: prior probability of a hypothesis
multiplied with probability of the hypothesis
given the training data
 Probabilistic hypothesis: outputs not only a
classification, but a probability distribution
over all classes
Bayes Classifiers
Assumption: training set consists of instances of different classes
described cj as conjunctions of attributes values
Task: Classify a new instance d based on a tuple of attribute values
into one of the classes cj  C
Key idea: assign the most probable class using Bayes
Theorem.
MAP
c
)
,
,
,
|
(
argmax 2
1 n
j
C
c
MAP x
x
x
c
P
c
j



)
,
,
,
(
)
(
)
|
,
,
,
(
argmax
2
1
2
1
n
j
j
n
C
c x
x
x
P
c
P
c
x
x
x
P
j 



)
(
)
|
,
,
,
(
argmax 2
1 j
j
n
C
c
c
P
c
x
x
x
P
j



Parameters estimation
 P(cj)
 Can be estimated from the frequency of classes in the
training examples.
 P(x1,x2,…,xn|cj)
 O(|X|n•|C|) parameters
 Could only be estimated if a very, very large number of
training examples was available.
 Independence Assumption: attribute values are
conditionally independent given the target value: naïve
Bayes.


i
j
i
j
n c
x
P
c
x
x
x
P )
|
(
)
|
,
,
,
( 2
1 



i
j
i
j
C
c
NB c
x
P
c
P
c
j
)
|
(
)
(
max
arg
Properties
 Estimating instead of greatly
reduces the number of parameters (and the data
sparseness).
 The learning step in Naïve Bayes consists of
estimating and based on the
frequencies in the training data
 An unseen instance is classified by computing the
class that maximizes the posterior
 When conditioned independence is satisfied, Naïve
Bayes corresponds to MAP classification.
)
|
( j
i c
x
P )
|
,
,
,
( 2
1 j
n c
x
x
x
P 
)
( j
c
P
)
|
( j
i c
x
P
Example. ‘Play Tennis’ data
Day Outlook Temperature Humidity Wind Play
Tennis
Day1 Sunny Hot High Weak No
Day2 Sunny Hot High Strong No
Day3 Overcast Hot High Weak Yes
Day4 Rain Mild High Weak Yes
Day5 Rain Cool Normal Weak Yes
Day6 Rain Cool Normal Strong No
Day7 Overcast Cool Normal Strong Yes
Day8 Sunny Mild High Weak No
Day9 Sunny Cool Normal Weak Yes
Day10 Rain Mild Normal Weak Yes
Day11 Sunny Mild Normal Strong Yes
Day12 Overcast Mild High Strong Yes
Day13 Overcast Hot Normal Weak Yes
Day14 Rain Mild High Strong No
Question: For the day <sunny, cool, high, strong>, what’s
the play prediction?
Naive Bayes solution
Classify any new datum instance x=(a1,…aT) as:
 To do this based on training examples, we need to estimate the
parameters from the training examples:
 For each target value (hypothesis) h
 For each attribute value at of each datum instance
)
(
estimate
:
)
(
ˆ h
P
h
P 
)
|
(
estimate
:
)
|
(
ˆ h
a
P
h
a
P t
t 



t
t
h
h
Bayes
Naive h
a
P
h
P
h
P
h
P
h )
|
(
)
(
max
arg
)
|
(
)
(
max
arg x
Based on the examples in the table, classify the following datum x:
x=(Outl=Sunny, Temp=Cool, Hum=High, Wind=strong)
 That means: Play tennis or not?
 Working:
)
|
(
)
|
(
)
|
(
)
|
(
)
(
max
arg
)
|
(
)
(
max
arg
)
|
(
)
(
max
arg
]
,
[
]
,
[
]
,
[
h
strong
Wind
P
h
high
Humidity
P
h
cool
Temp
P
h
sunny
Outlook
P
h
P
h
a
P
h
P
h
P
h
P
h
no
yes
h
t
t
no
yes
h
no
yes
h
NB











x
no
x
PlayTennis
answer
no
strong
P
no
high
P
no
cool
P
no
sunny
P
no
P
yes
strong
P
yes
high
P
yes
cool
P
yes
sunny
P
yes
P
etc
no
PlayTennis
strong
Wind
P
yes
PlayTennis
strong
Wind
P
no
PlayTennis
P
yes
PlayTennis
P


















)
(
:
)
|
(
)
|
(
)
|
(
)
|
(
)
(
0053
.
0
)
|
(
)
|
(
)
|
(
)
|
(
)
(
.
60
.
0
5
/
3
)
|
(
33
.
0
9
/
3
)
|
(
36
.
0
14
/
5
)
(
64
.
0
14
/
9
)
(
0.0206
Underflow Prevention
 Multiplying lots of probabilities, which are
between 0 and 1 by definition, can result in
floating-point underflow.
 Since log(xy) = log(x) + log(y), it is better to
perform all computations by summing logs of
probabilities rather than multiplying
probabilities.
 Class with highest final un-normalized log
probability score is still the most probable.





positions
i
j
i
j
C
c
NB c
x
P
c
P
c )
|
(
log
)
(
log
argmax
j

More Related Content

PPTX
Naive Bayes Presentation
PPT
original
PPTX
4-ML-UNIT-IV-Bayesian Learning.pptx
PPTX
-BayesianLearning in machine Learning 12
PPTX
Naive Bayes_1.pptx Slides of NB in classical machine learning
PPTX
Module 4 part_1
PDF
Machine Learning using python module_4_part_1.pdf
PPT
lecture13-nbbbbb. Bbnnndnjdjdjbayes.ppt
Naive Bayes Presentation
original
4-ML-UNIT-IV-Bayesian Learning.pptx
-BayesianLearning in machine Learning 12
Naive Bayes_1.pptx Slides of NB in classical machine learning
Module 4 part_1
Machine Learning using python module_4_part_1.pdf
lecture13-nbbbbb. Bbnnndnjdjdjbayes.ppt

Similar to bayesNaive.ppt (20)

PDF
lecture 5 about lecture 5 about lecture lecture
PPT
9-Decision Tree Induction-23-01-2025.ppt
PPTX
Bagging_and_Boosting.pptx
PPTX
Module 4_F.pptx
PDF
06 Machine Learning - Naive Bayes
PPTX
Naive Bayes.pptx
PDF
Bayesian Learning- part of machine learning
PPTX
UNIT II (7).pptx
PPTX
Bayesian Learning by Dr.C.R.Dhivyaa Kongu Engineering College
PDF
Bayesian Learning - Naive Bayes Algorithm
PDF
We can apply this process to neural networks and come up with the probability...
PPTX
Naive_hehe.pptx
PDF
PPT
ppt
PDF
Bayes Theorem.pdf
PDF
Bayesian regression algorithm for machine learning
PDF
Lecture10 - Naïve Bayes
PDF
An introduction to Bayesian Statistics using Python
PDF
[系列活動] Machine Learning 機器學習課程
PPTX
Supervised models
lecture 5 about lecture 5 about lecture lecture
9-Decision Tree Induction-23-01-2025.ppt
Bagging_and_Boosting.pptx
Module 4_F.pptx
06 Machine Learning - Naive Bayes
Naive Bayes.pptx
Bayesian Learning- part of machine learning
UNIT II (7).pptx
Bayesian Learning by Dr.C.R.Dhivyaa Kongu Engineering College
Bayesian Learning - Naive Bayes Algorithm
We can apply this process to neural networks and come up with the probability...
Naive_hehe.pptx
ppt
Bayes Theorem.pdf
Bayesian regression algorithm for machine learning
Lecture10 - Naïve Bayes
An introduction to Bayesian Statistics using Python
[系列活動] Machine Learning 機器學習課程
Supervised models
Ad

More from KhushiDuttVatsa (7)

PPTX
processing and marketing.pptx
PDF
Unit 2 Star Activity.pdf
PDF
Unit 3 Gene Transfer Techniques.pdf
PDF
Unit 2 Gene Cloning.pdf
PPTX
Southern-blotting-and-Western-blotting.pptx
PPTX
Lec13_Bayes.pptx
PPT
Bayes_Theorem.ppt
processing and marketing.pptx
Unit 2 Star Activity.pdf
Unit 3 Gene Transfer Techniques.pdf
Unit 2 Gene Cloning.pdf
Southern-blotting-and-Western-blotting.pptx
Lec13_Bayes.pptx
Bayes_Theorem.ppt
Ad

Recently uploaded (20)

PPTX
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
PPTX
PMP (Project Management Professional) course prepares individuals
PPTX
Surgical thesis protocol formation ppt.pptx
PPTX
E-Commerce____Intermediate_Presentation.pptx
PDF
Entrepreneurship PowerPoint for students
PPTX
The Stock at arrangement the stock and product.pptx
PPTX
Definition and Relation of Food Science( Lecture1).pptx
PPTX
Prokaryotes v Eukaryotes PowerPoint.pptx
PDF
Biography of Mohammad Anamul Haque Nayan
PPTX
AREAS OF SPECIALIZATION AND CAREER OPPORTUNITIES FOR COMMUNICATORS AND JOURNA...
PPTX
1751884730-Visual Basic -Unitj CS B.pptx
PDF
Prostaglandin E2.pdf orthoodontics op kharbanda
PDF
Sales and Distribution Managemnjnfijient.pdf
PDF
L-0018048598visual cloud book for PCa-pdf.pdf
PPTX
Principles of Inheritance and variation class 12.pptx
PPTX
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
PPTX
Your Guide to a Winning Interview Aug 2025.
PDF
MCQ Practice CBT OL Official Language 1.pptx.pdf
DOCX
mcsp232projectguidelinesjan2023 (1).docx
PPTX
Sports and Dance -lesson 3 powerpoint presentation
Nervous_System_Drugs_PPT.pptxXXXXXXXXXXXXXXXXX
PMP (Project Management Professional) course prepares individuals
Surgical thesis protocol formation ppt.pptx
E-Commerce____Intermediate_Presentation.pptx
Entrepreneurship PowerPoint for students
The Stock at arrangement the stock and product.pptx
Definition and Relation of Food Science( Lecture1).pptx
Prokaryotes v Eukaryotes PowerPoint.pptx
Biography of Mohammad Anamul Haque Nayan
AREAS OF SPECIALIZATION AND CAREER OPPORTUNITIES FOR COMMUNICATORS AND JOURNA...
1751884730-Visual Basic -Unitj CS B.pptx
Prostaglandin E2.pdf orthoodontics op kharbanda
Sales and Distribution Managemnjnfijient.pdf
L-0018048598visual cloud book for PCa-pdf.pdf
Principles of Inheritance and variation class 12.pptx
Autonomic_Nervous_SystemM_Drugs_PPT.pptx
Your Guide to a Winning Interview Aug 2025.
MCQ Practice CBT OL Official Language 1.pptx.pdf
mcsp232projectguidelinesjan2023 (1).docx
Sports and Dance -lesson 3 powerpoint presentation

bayesNaive.ppt

  • 2. Bayesian Methods  Our focus this lecture  Learning and classification methods based on probability theory.  Bayes theorem plays a critical role in probabilistic learning and classification.  Uses prior probability of each category given no information about an item.  Categorization produces a posterior probability distribution over the possible categories given a description of an item.
  • 3. Basic Probability Formulas  Product rule  Sum rule  Bayes theorem  Theorem of total probability, if event Ai is mutually exclusive and probability sum to 1 ) ( ) | ( ) ( ) | ( ) ( A P A B P B P B A P B A P    ) ( ) ( ) ( ) ( B A P B P A P B A P         n i i i A P A B P B P 1 ) ( ) | ( ) ( ) ( ) ( ) | ( ) | ( D P h P h D P D h P 
  • 4. Bayes Theorem  Given a hypothesis h and data D which bears on the hypothesis:  P(h): independent probability of h: prior probability  P(D): independent probability of D  P(D|h): conditional probability of D given h: likelihood  P(h|D): conditional probability of h given D: posterior probability ) ( ) ( ) | ( ) | ( D P h P h D P D h P 
  • 5. Does patient have cancer or not?  A patient takes a lab test and the result comes back positive. It is known that the test returns a correct positive result in only 99% of the cases and a correct negative result in only 95% of the cases. Furthermore, only 0.03 of the entire population has this disease. 1. What is the probability that this patient has cancer? 2. What is the probability that he does not have cancer? 3. What is the diagnosis?
  • 6. Maximum A Posterior  Based on Bayes Theorem, we can compute the Maximum A Posterior (MAP) hypothesis for the data  We are interested in the best hypothesis for some space H given observed training data D. ) | ( argmax D h P h H h MAP   ) ( ) ( ) | ( argmax D P h P h D P H h  ) ( ) | ( argmax h P h D P H h  H: set of all hypothesis. Note that we can drop P(D) as the probability of the data is constant (and independent of the hypothesis).
  • 7. Maximum Likelihood  Now assume that all hypotheses are equally probable a priori, i.e., P(hi ) = P(hj ) for all hi, hj belong to H.  This is called assuming a uniform prior. It simplifies computing the posterior:  This hypothesis is called the maximum likelihood hypothesis. ) | ( max arg h D P h H h ML  
  • 8. Desirable Properties of Bayes Classifier  Incrementality: with each training example, the prior and the likelihood can be updated dynamically: flexible and robust to errors.  Combines prior knowledge and observed data: prior probability of a hypothesis multiplied with probability of the hypothesis given the training data  Probabilistic hypothesis: outputs not only a classification, but a probability distribution over all classes
  • 9. Bayes Classifiers Assumption: training set consists of instances of different classes described cj as conjunctions of attributes values Task: Classify a new instance d based on a tuple of attribute values into one of the classes cj  C Key idea: assign the most probable class using Bayes Theorem. MAP c ) , , , | ( argmax 2 1 n j C c MAP x x x c P c j    ) , , , ( ) ( ) | , , , ( argmax 2 1 2 1 n j j n C c x x x P c P c x x x P j     ) ( ) | , , , ( argmax 2 1 j j n C c c P c x x x P j   
  • 10. Parameters estimation  P(cj)  Can be estimated from the frequency of classes in the training examples.  P(x1,x2,…,xn|cj)  O(|X|n•|C|) parameters  Could only be estimated if a very, very large number of training examples was available.  Independence Assumption: attribute values are conditionally independent given the target value: naïve Bayes.   i j i j n c x P c x x x P ) | ( ) | , , , ( 2 1     i j i j C c NB c x P c P c j ) | ( ) ( max arg
  • 11. Properties  Estimating instead of greatly reduces the number of parameters (and the data sparseness).  The learning step in Naïve Bayes consists of estimating and based on the frequencies in the training data  An unseen instance is classified by computing the class that maximizes the posterior  When conditioned independence is satisfied, Naïve Bayes corresponds to MAP classification. ) | ( j i c x P ) | , , , ( 2 1 j n c x x x P  ) ( j c P ) | ( j i c x P
  • 12. Example. ‘Play Tennis’ data Day Outlook Temperature Humidity Wind Play Tennis Day1 Sunny Hot High Weak No Day2 Sunny Hot High Strong No Day3 Overcast Hot High Weak Yes Day4 Rain Mild High Weak Yes Day5 Rain Cool Normal Weak Yes Day6 Rain Cool Normal Strong No Day7 Overcast Cool Normal Strong Yes Day8 Sunny Mild High Weak No Day9 Sunny Cool Normal Weak Yes Day10 Rain Mild Normal Weak Yes Day11 Sunny Mild Normal Strong Yes Day12 Overcast Mild High Strong Yes Day13 Overcast Hot Normal Weak Yes Day14 Rain Mild High Strong No Question: For the day <sunny, cool, high, strong>, what’s the play prediction?
  • 13. Naive Bayes solution Classify any new datum instance x=(a1,…aT) as:  To do this based on training examples, we need to estimate the parameters from the training examples:  For each target value (hypothesis) h  For each attribute value at of each datum instance ) ( estimate : ) ( ˆ h P h P  ) | ( estimate : ) | ( ˆ h a P h a P t t     t t h h Bayes Naive h a P h P h P h P h ) | ( ) ( max arg ) | ( ) ( max arg x
  • 14. Based on the examples in the table, classify the following datum x: x=(Outl=Sunny, Temp=Cool, Hum=High, Wind=strong)  That means: Play tennis or not?  Working: ) | ( ) | ( ) | ( ) | ( ) ( max arg ) | ( ) ( max arg ) | ( ) ( max arg ] , [ ] , [ ] , [ h strong Wind P h high Humidity P h cool Temp P h sunny Outlook P h P h a P h P h P h P h no yes h t t no yes h no yes h NB            x no x PlayTennis answer no strong P no high P no cool P no sunny P no P yes strong P yes high P yes cool P yes sunny P yes P etc no PlayTennis strong Wind P yes PlayTennis strong Wind P no PlayTennis P yes PlayTennis P                   ) ( : ) | ( ) | ( ) | ( ) | ( ) ( 0053 . 0 ) | ( ) | ( ) | ( ) | ( ) ( . 60 . 0 5 / 3 ) | ( 33 . 0 9 / 3 ) | ( 36 . 0 14 / 5 ) ( 64 . 0 14 / 9 ) ( 0.0206
  • 15. Underflow Prevention  Multiplying lots of probabilities, which are between 0 and 1 by definition, can result in floating-point underflow.  Since log(xy) = log(x) + log(y), it is better to perform all computations by summing logs of probabilities rather than multiplying probabilities.  Class with highest final un-normalized log probability score is still the most probable.      positions i j i j C c NB c x P c P c ) | ( log ) ( log argmax j