Calculate Posterior Probability Using Bayes' Theorem Example
Quick Overview
This question evaluates understanding of Bayes' theorem and probabilistic reasoning for computing posterior probabilities in binary classification, emphasizing priors, likelihoods, and conditional probability.
Calculate Posterior Probability Using Bayes' Theorem Example
Company: Snapchat
Role: Data Scientist
Category: Statistics & Math
Difficulty: easy
Interview Round: Technical Screen
##### Scenario
Interviewers want to test your understanding of Bayes’ theorem using a straightforward numerical example (e.g., medical-test or spam-detection toy problem).
##### Question
Walk through a complete Bayes-theorem calculation:
1) clearly define prior P(H) and likelihoods P(E|H), P(E|¬H);
2) write the full formula;
3) compute the posterior P(H|E) and report the final numeric answer.
##### Hints
State assumptions, show every step, then simplify to one decimal/fraction.
Quick Answer: This question evaluates understanding of Bayes' theorem and probabilistic reasoning for computing posterior probabilities in binary classification, emphasizing priors, likelihoods, and conditional probability.
Calculate Posterior Probability Using Bayes' Theorem Example
Snapchat
Jul 12, 2025, 6:59 PM
easyData ScientistTechnical ScreenStatistics & Math
27
0
Bayes' Theorem: Spam-Flag Posterior
You are evaluating a simple classifier that flags messages as spam. From historical data you know the spam prevalence and the classifier's performance (true-positive and false-positive rates). A message has just been flagged. Compute the probability that it is actually spam.
You are given:
Prior spam rate:
2% of all messages are spam.
True-positive rate:
if a message is spam, the classifier flags it 90% of the time.
False-positive rate:
if a message is
not
spam, the classifier still flags it 5% of the time.
Produce a complete, step-by-step Bayes-theorem solution:
Define the events, the prior
P(H)
, and the likelihoods
P(E∣H)
and
P(E∣¬H)
.
Write the full posterior formula.
Compute the posterior
P(H∣E)
and report the final numeric answer.
Show every step, state your assumptions, and simplify the final answer to a clear fraction and a one-decimal-place percentage.
Constraints & Assumptions
The three given numbers — prior
P(H)=0.02
,
P(E∣H)=0.90
,
P(E∣¬H)=0.05
— are treated as exact.
"Flagged" is a single binary event
E
; the two classes (spam / not spam) are mutually exclusive and exhaustive, so
P(¬H)=1−P(H)=0.98
.
A "spam" message and a flag are well-defined; no abstention, no third class, no time dependence in the rates.
Clarifying Questions to Ask
Is the 2% the
unconditional
prior over
all
messages, or already conditioned on some pre-filter? (It changes the base rate that drives the answer.)
Is the 5% figure the false-positive rate
P(E∣¬H)
, or is it the
specificity
? (If specificity, then
P(E∣¬H)=1−specificity
.)
Are the rates stable across message types/time, or should I expect them to drift (motivating later calibration)?
What is the downstream cost of a false positive vs. a missed spam — i.e. is the relevant target the posterior, or a threshold chosen to balance those costs?
What a Strong Answer Covers
Correct mapping
of the three given numbers to
P(H)
,
P(E∣H)
,
P(E∣¬H)
, and explicit derivation of
P(¬H)
.
Right inferential direction:
computes
P(H∣E)
and explains why it differs sharply from the 90% true-positive rate.
Law of total probability
used to build the denominator
P(E)
, not an unjustified value.
Arithmetic
that lands on the exact fraction and its decimal/percentage form.
Interpretation of the base-rate effect:
articulates
why
a strong detector yields a modest posterior when spam is rare.
Optional but valued: a
natural-frequency cross-check
confirming the algebra.
Follow-up Questions
The product team wants the flagged set to be at least 80% truly spam (precision
≥0.80
). Holding the prior fixed, what false-positive rate would you need, and is that realistic?
If the true spam prevalence doubled to 4%, what happens to the posterior, and which input has more leverage on it — the prior or the false-positive rate?
How would you extend this from a single posterior to a full
precision–recall
trade-off as you sweep the classifier's decision threshold?
The classifier outputs a continuous score, not a hard flag. How would you reason about
P(spam∣score=s)
, and how would you check that the scores are
calibrated
?