Professional Documents
Culture Documents
1
Quick slide reference
Conditional
Probability
3
Dice, our misunderstood friends
Roll two 6-sided dice, yielding
values 𝐷1 and 𝐷2 .
𝑆 = 36
𝐸 = 1,3 , 2, 2 , 3,1
𝑃 𝐸 = 3/36 = 1/12
|𝐸𝐹|
𝑃 𝐸𝐹 = 8
|𝐹| 𝑃 𝐸 = ≈ 0.16
50
3
𝑃 𝐸𝐹 = ≈ 0.21
14
Lisa Yan, CS109, 2020 6
𝐸𝐹 Equally likely
Slicing up the spam 𝑃 𝐸|𝐹 =
|𝐹| outcomes
≈ 0.3245 ≈ 0.0784 =0
No way to choose 5 spam from
4 remaining spam emails!
Lisa Yan, CS109, 2020 8
Conditional probability in general
≈ 0.42
Lisa Yan, CS109, 2020 13
𝑃 𝐸𝐹 Definition of
Netflix and Learn 𝑃 𝐸|𝐹 =
𝑃(𝐹) Cond. Probability
𝑃 𝐸|𝐹 = 0.14 𝑃 𝐸|𝐹 = 0.35 𝑃 𝐸|𝐹 = 0.20 𝑃 𝐸|𝐹 = 0.72 𝑃 𝐸|𝐹 = 0.42
Lisa Yan, CS109, 2020 14
04b_total_prob
Law of Total
Probability
15
Today’s tasks
𝑃 𝐸𝐹
Chain rule Definition of
(Product rule) conditional probability
𝑃 𝐸|𝐹
Law of Total
Probability
𝑃(𝐸) = 𝑃 𝐸|𝐹𝑖 𝑃 𝐹𝑖
𝑖=1
1. Define events
& state goal
Bayes’ Theorem
I
22
Today’s tasks
𝑃 𝐸𝐹
Chain rule Definition of
(Product rule) conditional probability
𝑃 𝐸|𝐹
Law of Total Bayes’
Probability Theorem
We can easily calculate how many But what is the probability that an
spam emails contain “Dear”: email containing “Dear” is spam?
Spam Spam “Dear”
𝑃 𝐸 𝐹 = 𝑃 “Dear” ቚ 𝑃 𝐹𝐸 =𝑃 ቚ
email email
Lisa Yan, CS109, 2020 25
(silent drumroll)
26
Bayes’ Theorem 𝑃 𝐸|𝐹 𝑃 𝐹|𝐸
Expanded form:
𝑃 𝐸𝐹 𝑃 𝐹
𝑃 𝐹𝐸 = 𝐶
Proof
𝑃 𝐸|𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐹 𝑃(𝐹 𝐶 )
1 more step! See board
Lisa Yan, CS109, 2020 27
𝑃 𝐸𝐹 𝑃 𝐹 Bayes’
Detecting spam email 𝑃 𝐹𝐸 =
𝑃 𝐸|𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐹 𝐶 𝑃(𝐹 𝐶 ) Theorem
likelihood prior
posterior
𝑃 𝐸𝐹 𝑃 𝐹
𝑃 𝐹𝐸 =
𝑃 𝐸
normalization constant
Lisa Yan, CS109, 2020 30
(live)
04: Conditional
Probability and Bayes
Slides by Lisa Yan
June 29, 2020
31
This class going forward
𝑃 𝐸 = Evidence | 𝐹 = Fact
(collected from data)
𝐸 given some evidence
Bayes’
𝑃
has been observed
𝑃 𝐹 = Fact | 𝐸 = Evidence
(categorize
𝑃 𝐸∩𝐹 𝑃 𝐸∪𝐹 a new datapoint)
(counting, combinatorics)
🤔
34
Think, then groups
You have a flowering plant. E
0.05
Let 𝐸 = Flowers bloom 0.05 0.05
0.1
𝐹 = Plant was watered 0.15 0.2
𝐺 = Plant got sun F
0.2
G
1. How would you write
i. the probability that the plant got sun,
given that it was watered and flowers bloomed?
ii. the probability that the plant got sun
and flowers bloomed given that it was watered?
2. Using the Venn diagram, compute the above probabilities.
3. Chain Rule: Fill in the blanks.
i. 𝑃 𝐺𝐸 = _______ ⋅ 𝑃 𝐸
ii. 𝑃 𝐺𝐸|𝐹 = 𝑃 𝐺|𝐸𝐹 ⋅ _______
Lisa Yan, CS109, 2020
🤔 35
LIVE
Bayes’ Theorem
II
37
Why is Bayes’ so important?
Mathematically:
𝑃 𝐸 𝐹 → 𝑃 𝐹|𝐸
Real-life application:
Given new evidence 𝐸, update belief of fact 𝐹
Prior belief → Posterior belief
𝑃 𝐹 → 𝑃 𝐹|𝐸
Lisa Yan, CS109, 2020 39
Zika, an autoimmune disease
Take
test
Fact, 𝐹 Has disease Evidence, 𝐸 Test positive
or 𝐹 𝐶 No disease or 𝐸 𝐶 Test negative
Fact
𝐹, disease + 𝐹 𝐶 , disease – If a test returns positive,
True positive False positive what is the likelihood
𝐸, Test +
Evidence
Take
test
Fact, 𝐹 Has disease Evidence, 𝐸 Test positive
or 𝐹 𝐶 No disease or 𝐸 𝐶 Test negative
Fact
𝐹, disease + 𝐹 𝐶 , disease – If a test returns positive,
True positive False positive what is the likelihood
𝐸, Test +
Evidence
Breakout https://us.edstem.org/courses/667/discussion/83250
🤔
43
𝑃 𝐸𝐹 𝑃 𝐹 Bayes’
Zika Testing 𝑃 𝐹𝐸 =
𝑃 𝐸|𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐹 𝐶 𝑃(𝐹 𝐶 ) Theorem
1. Define events
& state goal
Let: 𝐸 = you test positive
𝐹 = you actually have
the disease
Want:
P(disease | test+)
= 𝑃 𝐹|𝐸
Lisa Yan, CS109, 2020
🤔 44
𝑃 𝐸𝐹 𝑃 𝐹 Bayes’
Zika Testing 𝑃 𝐹𝐸 =
𝑃 𝐸|𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐹 𝐶 𝑃(𝐹 𝐶 ) Theorem
All People
Original question:
What is the likelihood
you have Zika if you
test positive for the People who test positive
disease?
The space
of facts
Lisa Yan, CS109, 2020 47
Bayes’ Theorem intuition
All People
Original question:
What is the likelihood
you have Zika if you
test positive for the People who test positive
disease?
Interpret
People with Zika
Interpretation:
Of the people who test
positive, how many actually
The space
have Zika?
of facts
Lisa Yan, CS109, 2020 48
Bayes’ Theorem intuition
Interpret
⚠️
𝑃 𝐹 𝑃 𝐹|𝐸
Lisa Yan, CS109, 2020 51
Interlude for
fun/announcements
52
Topical probability news: Bayes for COVID-19 testing
P(Innocent|Evidence)
versus
P(Evidence|Innocent)
DNA matches
Guilty
https://www.cebm.net/2018/07/the-prosecutors-fallacy/
🤔
(by yourself)
56
𝑃 𝐸𝐹 𝑃 𝐹 Bayes’
Why it’s still good to get tested 𝑃 𝐹𝐸 =
𝑃 𝐸|𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐹 𝐶 𝑃(𝐹 𝐶 ) Theorem
57
𝑃 𝐸𝐹 𝑃 𝐹 Bayes’
Why it’s still good to get tested 𝑃 𝐹𝐸 =
𝑃 𝐸|𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐹 𝐶 𝑃(𝐹 𝐶 ) Theorem
𝑃 𝐸𝐶 𝐹 𝑃 𝐹
𝑃 𝐹 𝐸𝐶 =
𝑃 𝐸 𝐶 |𝐹 𝑃 𝐹 + 𝑃 𝐸 𝐶 𝐹 𝐶 𝑃(𝐹 𝐶 )
𝑃 𝐹|𝐸
⚠️
I have a 0.5%
chance of having With these test results,
Zika disease. I now have a 0.01%
chance of having Zika
disease!!!
𝑃 𝐹
Lisa Yan, CS109, 2020
𝑃 𝐹|𝐸 𝐶 ✅ 60
Topical probability news: Bayes for COVID-19 testing
• Antibody tests (blood samples)
have higher false negative, false
positive rates than RT-PCR tests
(nasal swab). However, they help
explain/identify our body’s reaction
to the virus.
• The real world has many more
“givens” (current symptoms, How representative are today’s
existing medical conditions) that testing rates?
improve our belief prior to testing. How do we know if a positive test is
• Most importantly, testing gives us a a true positive or a false positive?
noisy signal of the spread of a Why test if there are errors?
disease.
Lisa Yan, CS109, 2020 61
LIVE
Monty Hall
Problem
63
Monty Hall Problem
and Wayne Brady
Next Time:
Independence!
68