10 Bayes Theorem
10 Bayes Theorem
Foundations of Computing II
Lecture 5: Conditional Probability and Bayes Theorem
Anna R. Karlin
Slide Credit: Based on Stefano Tessaro’s slides for 312 19au
incorporating ideas from Alex Tsun, Rachel Lin, Hunter Schafer & myself J
1
Thank you for your feedback!!!
2
Review Probability
Examples:
Definition. A sample space Ω is the set of
• Single coin flip: Ω = {𝐻, 𝑇}
all possible outcomes of an experiment.
• Two coin flips: Ω = {𝐻𝐻, 𝐻𝑇, 𝑇𝐻, 𝑇𝑇}
• Roll of a die: Ω = 1, 2, 3, 4, 5, 6
Examples:
Definition. An event 𝐸 ⊆ Ω is a subset of • Getting at least one head in two coin flips:
possible outcomes. 𝐸 = {𝐻𝐻, 𝐻𝑇, 𝑇𝐻}
• Rolling an even number on a die :
𝐸 = {2, 4, 6}
3
Review Axioms of Probability
4
Agenda
• Conditional Probability
• Bayes Theorem
• Law of Total Probability
• Bayes Theorem + Law of Total Probability
• More Examples
5
Conditional Probability (Idea)
A B
36 7 13
14
What’s the probability that someone likes ice cream given they like donuts?
6
Conditional Probability
𝑃 𝐴 ∩ 𝐵 = 𝑃 𝐴 𝐵 𝑃(𝐵)
7
Reversing Conditional Probability
𝑃 𝐴𝐵 =1
𝑃 𝐵𝐴 ≠1
9
Example with Conditional Probability
https://pollev.com/ annakarlin185
P(𝐵) 𝑃(𝐵|𝐴)
Toss a red die and a blue die (both 6 a) 1/6 1/6
sided and all outcomes equally b) 1/6 1/3
likely). What is 𝑃 𝐵 ? What is c) 1/6 3/36
d) 1/9 1/3
𝑃(𝐵|𝐴)?
10
Gambler’s fallacy
Assume we toss 51 fair coins.
Assume we have seen 50 coins, and they are all “tails”.
What are the odds the 51st coin is “heads”?
ℙ ℬ𝒜 =
11
Gambler’s fallacy
Assume we toss 51 fair coins.
Assume we have seen 50 coins, and they are all “tails”.
What are the odds the 51st coin is “heads”?
• Conditional Probability
• Bayes Theorem
• Law of Total Probability
• Bayes Theorem + Law of Total Probability
• More Examples
13
Bayes Theorem
𝑃 𝐵 𝐴 𝑃(𝐴)
𝑃 𝐴𝐵 =
𝑃(𝐵)
Swapping A, B gives
𝑃 𝐵∩𝐴 =𝑃 𝐵 𝐴 𝑃 𝐴
15
Our First Machine Learning Task: Spam Filtering
What is the probability this email is spam, given the subject contains “FREE”?
Some useful stats:
– 10% of ham (i.e., not spam) emails contain the word “FREE” in the subject.
– 70% of spam emails contain the word “FREE” in the subject.
– 80% of emails you receive are spam.
16
Brain Break
17
Agenda
• Conditional Probability
• Bayes Theorem
• Law of Total Probability
• Bayes Theorem + Law of Total Probability
• More Examples
18
Partitions (Idea)
19
Partition
Definition. Non-empty events 𝐸" , 𝐸# , … , 𝐸$ partition the sample space Ω if
(Exhaustive)
1
𝐸/ ∪ 𝐸0 ∪ ⋯ ∪ 𝐸1 = 0 𝐸2 = Ω
23/
(Pairwise Mutually Exclusive)
∀2 ∀245 𝐸2 ∩ 𝐸5 = ∅
EC E
20
Law of Total Probability (Idea)
21
Law of Total Probability (LTP)
Definition. If events 𝐸" , 𝐸# , … , 𝐸$ partition the sample space Ω, then for any event F
$
𝑃 𝐹 = 𝑃 𝐹 ∩ 𝐸" + … + 𝑃 𝐹 ∩ 𝐸$ = 8 𝑃(𝐹 ∩ 𝐸% )
%&"
𝑃 𝐹 = 6 𝑃 𝐹 𝐸2 𝑃(𝐸2 )
23/
22
Another Contrived Example
What is ℙ R ?
23
Sequential Process – Non-Uniform Case
Right Red • Left pocket: Two red, two green
• Right pocket: One red, two green.
Right
Right Green
• Alice picks a random ball from a
Left Red random pocket
Left
Left Green
24
Sequential Process – Non-Uniform Case
1/3 RR • Left pocket: Two red, two green
• Right pocket: One red, two green.
1/2 Right
2/3 RG
1/2
1/3 = 𝒫 𝑅 R) and 2/3 = 𝒫 𝐺 R)
LR
1/2 Left
1/2 LG
• Conditional Probability
• Bayes Theorem
• Law of Total Probability
• Bayes Theorem + Law of Total Probability
• More Examples
26
Our First Machine Learning Task: Spam Filtering
What is the probability this email is spam, given the subject contains “FREE”?
Some useful stats:
– 10% of ham (i.e., not spam) emails contain the word “FREE” in the subject.
– 70% of spam emails contain the word “FREE” in the subject.
– 80% of emails you receive are spam.
27
Bayes Theorem with Law of Total Probability
• Conditional Probability
• Bayes Theorem
• Law of Total Probability
• Bayes Theorem + Law of Total Probability
• More Examples
29
Example – Zika Testing
Usually no or mild symptoms (rash); sometimes
severe symptoms (paralysis).
This example and following slides are from Lisa Yan (Stanford). 30
Example – Zika Testing
What is the probability you have Zika (event Z) if you test positive (event T).
https://pollev.com/ annakarlin185
What is the probability you have Zika (event Z) if you test positive (event T).
32
Example – Zika Testing Have zika blue, don’t pink
What is the probability you have Zika (event Z) if you test positive (event T).
5 1
= ≈ 0.33
5 + 10 3
Demo 33
Philosophy – Updating Beliefs
While it’s not 98% that you have the disease, your beliefs changed drastically
35
Conditional Probability Define a Probability Space
The probability conditioned on 𝐴 follows the same properties as
(unconditional) probability.
Example. ℙ ℬ 7 𝒜 = 1 − ℙ(ℬ|𝒜)
36
Conditional Probability Define a Probability Space
The probability conditioned on 𝐴 follows the same properties as
(unconditional) probability.
Example. ℙ ℬ 7 𝒜 = 1 − ℙ(ℬ|𝒜)
37