Math 32 - 06 - Bayes Rule (Examples)
Math 32 - 06 - Bayes Rule (Examples)
Math 32 - 06 - Bayes Rule (Examples)
1
Math 32 Lecture 6: Bayes Rule (Concepts) Spring 2021
In 2002, Paul Graham used Bayes’ Rule as part of his algorithms to greatly
decrease false positive rates of unwanted e-mails (“spam”).1 Let H c be the
event that an e-mail is ”spam”. Let W be the event that an e-mail contains
a trigger word such as “watches”. Suppose that
• the probability that an e-mail contains that word given that it is spam
is 17%
• the probability that an e-mail contains that word given that it is not
spam is 9%
• the probability that a randomly selected e-mail message is spam is 80%
Find the probability that an e-mail message is spam, given that the trigger
word appears.
c P (W |H c ) · P (H c )
P (H |W ) =
P (W |H c ) · P (H c ) + P (W |H) · P (H)
(0.17)(0.80)
=
(0.17)(0.80) + (0.09)(0.20)
≈ 0.8831
The probability that an e-mail message is spam given that the trigger word
appears is about 88.31 percent.
1 Source: http://en.wikipedia.org/wiki/Naive_Bayes_spam_filtering
2
Math 32 Lecture 6: Bayes Rule (Concepts) Spring 2021
A breath analyzer, used by the police to test whether drivers exceed the legal
limit set for the blood alcohol percentage while driving, is known to satisfy
P (A|B) = P (Ac |B c ) = x
where A is the event “breath analyzer indicates that legal limit is exceeded”
and B “driver’s blood alcohol percentage exceeds legal limit.” On Saturday
nights, about 5% of the drivers are known to exceed the limit.
1. Describe in words the meaning of P (B c |A)
2. Determine P (B c |A) if x = 0.95
3. How big should x be so that P (B|A) = 0.9?
2.1 Interpretation
P (B c |A) is the probability that the driver is sober given that the breath
analyzer claimed the driver was drunk (i.e. the probability of a false positive).
3
Math 32 Lecture 6: Bayes Rule (Concepts) Spring 2021
c P (A|B c ) · P (B c )
P (B |A) =
P (A|B c ) · P (B c ) + P (A|B) · P (B)
We need to compute the complements,
• P (B c ) = 1 − P (B)
• P (A|B c ) = 1 − P (Ac |B c )
c P (A|B c ) · P (B c )
P (B |A) =
P (A|B c ) · P (B c ) + P (A|B) · P (B)
[1 − P (Ac |B c )] · [1 − P (B)]
=
[1 − P (Ac |B c )] · [1 − P (B)] + P (A|B) · P (B)
(1 − 0.95) · (1 − 0.05)
=
(1 − 0.95) · (1 − 0.05) + (0.95)(0.05)
= 0.5
The probability that the driver is sober given that the breath analyzer claimed
the driver was drunk (i.e. the probability of a false positive) is 50 percent!
4
Math 32 Lecture 6: Bayes Rule (Concepts) Spring 2021
What should the sensitivity and specificity of the blood alcohol test be so
that that the probability the driver is drunk given a positive test is 90 percent
(P (B|A) = 0.9)?
P (A|B) = P (Ac |B c ) = x
Using Bayes’ Rule,
P (A|B) · P (B)
P (B|A) =
P (A|B) · P (B) + P (A|B c ) · P (B c )
P (A|B) · P (B)
P (B|A) =
P (A|B) · P (B) + [1 − P (Ac |B c )] · [1 − P (B)])
0.05x
0.9 ≤
0.05x + (1 − 0.05)(1 − x)
The sensitivity and specificity each need to exceed x ≈ 0.9942 so that
P (B|A) ≥ 0.9.
5
Math 32 Lecture 6: Bayes Rule (Concepts) Spring 2021
P (C|H) · P (H)
P (H|C) =
P (C|H) · P (H) + P (C|H c ) · P (H c )
(0.32)(0.02)
=
(0.32)(0.02) + (0.13)(0.98)
≈ 0.0478
The probability that a freshman has herpes, given that you know that he or
she lived in the Cathedral dorm is about 4.78%.
6
Math 32 Lecture 6: Bayes Rule (Concepts) Spring 2021
A = {A1 , A2 , ..., Aj }
then the total probability is
P (B|Ai ) · P (Ai )
P (Ai |B) =
P (B|A1 ) · P (A1 ) + P (B|A2 ) · P (A2 ) + ... + P (B|An ) · P (An )