ML Interview Q Series: Calculating Rain Probability Using Bayes' Theorem and Unreliable Sources
Browse all the Probability Interview Questions here.
Question: You are getting ready to fly to Seattle and want to know if you should bring an umbrella. You contact three friends there, each with an independent 2/3 probability of telling the truth and a 1/3 chance of lying. All three claim that it is raining. What is the probability it is actually raining?
Comprehensive Explanation
A good way to solve this is by applying Bayes’ theorem. We label the event that it is raining as R, and the event that all three friends say “Yes” as A (for “all say yes”). We want to compute P(R given A).
We typically assume that the prior probability P(R) is 0.5 (no specific prior is given in the question, so it is usual to assume an equal chance that it might be raining or not). Each friend speaks independently, with probability 2/3 of telling the truth and 1/3 of lying.
When it is raining, a friend says “Yes” with probability 2/3. So if it is raining, the probability that all three say “Yes” is (2/3)^3. When it is not raining, each friend lies with probability 1/3, so the chance of a friend saying “Yes” in that scenario is 1/3; therefore, for all three saying “Yes,” we get (1/3)^3.
We combine these facts with Bayes’ theorem:
In this expression:
P(R) is the prior probability it is raining (assumed 0.5).
P(neg R) = 1 - P(R) = 0.5.
P(all yes | R) is (2/3)^3.
P(all yes | neg R) is (1/3)^3.
Substituting these values:
Numerator = (2/3)^3 * 0.5 = (8/27) * 0.5 = 4/27.
Denominator = (8/27)*0.5 + (1/27)*0.5 = 4/27 + 0.5/27 = (4 + 0.5)/27 = 4.5/27 = 0.5 * (9/27) = 4.5/27.
Hence:
(4/27) / (4.5/27) = 4 / 4.5 = 8/9.
Thus the probability it is actually raining, given that all three friends say “Yes,” is 8/9.
What if the prior probability is different?
If we do not assume a 50% prior, say the prior probability is p that it is raining, then P(neg R) = 1 - p. The probability that all three say “Yes” if it is raining is still (2/3)^3, and if it is not raining it remains (1/3)^3. The formula in that case becomes:
P(R given A) = [ (2/3)^3 * p ] / [ (2/3)^3 * p + (1/3)^3 * (1 - p ) ].
You can plug in any value for p to get a more general posterior probability.
Why do we assume the friends are independent?
The problem states that each friend’s response is independent. In real scenarios, this may not hold if, for example, the friends communicate with each other or share similar biases. But we assume independence for simplicity, so the joint probability factors as the product of individual probabilities.
Could correlation among friends change the answer?
Yes. If one friend’s lie (or truth-telling) influenced another’s response, the probability of all three saying “Yes” would no longer be the simple product of individual probabilities. A more complex model would be needed to handle correlated judgments. In practice, this could change the final probability significantly, especially if one friend’s response heavily influences the others.
How does the scenario change if some friends are more reliable than others?
If each friend had a different probability of telling the truth, you would need to account for each friend’s reliability separately. Suppose friend 1 has probability a of telling the truth, friend 2 has probability b, and friend 3 has probability c. You would then calculate P(all say “Yes” | R) as a * b * c, and P(all say “Yes” | neg R) as (1 - a) * (1 - b) * (1 - c). The rest of the Bayesian calculation remains the same, but the numbers differ depending on each friend’s reliability.
Could we solve this using a frequentist approach?
A frequentist might reason that if each friend is truthful 2/3 of the time, then in repeated trials, we observe the proportion of times all three say “Yes” when it’s actually raining versus when it’s not. However, since the question is essentially a posterior probability question, Bayesian reasoning is the most direct path. A frequentist approach would also need additional assumptions and framing for what is being estimated or tested, but it would not be as straightforward for a single event probability.
Edge cases where the lying probability is extreme
If the lying probability were 0 (always truth) or 1 (always lying), the answer would become trivial. For example, if each friend always told the truth, the probability would be 1 that it is raining if they all said “Yes.” If each friend always lied, you would invert the logic for their statements. Intermediate probabilities, as in the original scenario, require a Bayesian approach to quantify the impact of their statements on your belief.
Implementation Example in Python
Below is a simple Python snippet showing how you might calculate the posterior probability when the prior can vary. This is a toy example, just to illustrate the computation:
def posterior_probability_of_rain(prior_p):
prob_yes_rain = (2/3)**3 # Probability all say yes given raining
prob_yes_no_rain = (1/3)**3 # Probability all say yes given not raining
numerator = prob_yes_rain * prior_p
denominator = numerator + prob_yes_no_rain * (1 - prior_p)
return numerator / denominator
# Example usage with prior = 0.5
print(posterior_probability_of_rain(0.5)) # Should output 0.888888...
This computation confirms that the answer is 8/9 when the prior is 0.5.
Below are additional follow-up questions
What if two friends said “Yes” and one said “No”?
In a more general scenario where not all friends agree, we would revise our Bayesian analysis. Instead of the probability that “all three say yes,” we would calculate the likelihood of “two yes and one no” under both the “raining” and “not raining” hypotheses. Specifically:
Probability of two yes and one no given it is raining: Each friend tells the truth with probability 2/3 and lies with probability 1/3. To get two yes and one no when it is raining, exactly two must speak truth (and thus say “Yes”) and one must lie (and thus say “No”). The probability for one specific arrangement (like Friend1 & Friend2 say yes, Friend3 says no) is (2/3 * 2/3 * 1/3). Because there are three possible ways to choose which friend lies, we multiply by 3, giving 3 * (2/3 * 2/3 * 1/3).
Probability of two yes and one no given it is not raining: Now yes is a lie and no is the truth. Two must lie and one must tell the truth. For a single specific arrangement, that probability is (1/3 * 1/3 * 2/3). Again we have three permutations, so multiply by 3.
Then we apply Bayes’ theorem using these new likelihoods (replacing “all yes” with “two yes and one no”), and multiply each by the prior probability that it is raining or not. The result gives the posterior probability of rain given the observed outcome. This approach generalizes to any combination of yes/no responses.
One subtlety: if you observe two yes and one no, you should weigh how likely it is that the “no” friend is lying or telling the truth. This is accounted for in the terms above but is worth highlighting as an intuitive cross-check.
How would the analysis change if “Yes” and “No” were not equally likely lies?
Sometimes the question might imply that lying about something being rainy could be more or less probable than lying about it not being rainy. For instance, a friend could be more inclined to say it is raining as a “practical joke” than to lie in the other direction. That would mean the probability of a friend saying “Yes” when it is not raining might differ from the standard 1/3.
To handle this, we would replace the simple (2/3) and (1/3) with more general parameters, say p(Truth | R) and q(Lie | not R). The structure of Bayes’ theorem remains, but the probabilities of each outcome (e.g., “Yes” or “No”) must be adjusted to reflect these asymmetries. Carefully collecting or estimating these parameters would be important in real-world settings where lies might not be uniformly distributed.
How does prior knowledge about Seattle’s typical weather patterns factor in?
If you know, for example, that Seattle typically has a 70% chance of rain on any given day, you would set your prior probability that it is raining to 0.7 rather than 0.5. With that prior, the posterior probability of rain given that all three friends say “Yes” increases even more compared to the 8/9 result under a 50/50 prior. The Bayesian formula accommodates this shift by weighing the new evidence (the unanimous “Yes”) against a higher baseline likelihood of rain.
The pitfall is assuming an incorrect prior. If your prior is wildly inaccurate (e.g., you assume it rains 99% of the time in a desert), your posterior can be misleading. Hence, calibrating the prior with realistic historical or contextual data is vital.
Could practical decision-making override the calculated probability?
In a purely probabilistic sense, if you get a posterior of, say, 0.9 that it is raining, you might decide to bring an umbrella. But in real life, you might also consider the cost or hassle of bringing an umbrella versus the inconvenience of being caught in the rain without one. If carrying an umbrella is not a big deal, even a moderate probability (e.g., 0.4 or 0.5) might prompt you to bring it. Conversely, if you have a strong aversion to lugging an umbrella around, you might only bring it if the probability is very high.
This highlights the difference between a strict Bayesian calculation and a cost-benefit decision-making process. The probability helps inform the decision, but your personal preferences and risk tolerance can change the final choice.
How does the scenario change if you can ask each friend multiple times?
If you can ask each friend the same question multiple times independently, you might gather more “Yes” or “No” answers from the same person, effectively increasing your sample size. For each friend, the responses could be considered Bernoulli trials with probability 2/3 of matching the truth and 1/3 of contradicting it. Aggregating repeated answers from the same friend can refine your estimate of whether they are currently being truthful or messing with you.
A subtlety is that real people might not maintain the same exact probability of lying/truth-telling across multiple queries, especially if they notice you are “testing” them. So independence might break down in practice. In an idealized scenario where each new query is truly independent, repeated questioning can reduce uncertainty by consistent repetition of the friend’s typical pattern (truthful or lying).
How to approach it if friends have different biases or additional context?
Suppose one friend is known to usually be straightforward (truth probability 0.9) while another often jokes (truth probability 0.5). In that case, each friend’s statement must be weighted accordingly. You would compute P(all yes | R) by multiplying each friend’s probability of saying “Yes” given R: (0.9 * 0.5 * 0.6), for instance, if the third friend has 0.6 probability of truth. Similarly, for not R, you combine the appropriate probabilities that they would say “Yes” as a lie.
Additionally, if a friend is physically looking outside while answering, you might consider their response more trustworthy than someone who is just guessing. Context like that modifies each friend’s reliability, which you reflect in the model. Without carefully addressing these different biases or contexts, your final posterior might be inaccurate.
What if each friend gave a confidence estimate instead of a strict yes/no?
If each friend says something like “I’m 70% sure it’s raining” instead of just “Yes” or “No,” the data becomes richer. Instead of a binary response, you have a conditional probability distribution from each friend. For instance, friend 1 might say “70%,” friend 2 says “90%,” and friend 3 says “60%.”
Modeling these partial beliefs is more complex: you would treat each friend’s response as an observation about the state of the world with some associated noise model. A Bayesian approach can incorporate these probabilities as likelihood functions, which would likely involve integrals over the range of reported confidences. The advantage is that you can get a more nuanced view of each friend’s belief. The pitfall is you must also accurately model how a friend’s reported confidence correlates with the truth.
What are potential numerical stability issues when implementing this in code?
When computing very small probabilities (e.g., (1/3)^3) repeatedly or combining them in denominators, floating-point precision might cause numerical underflow or inaccuracies. This is especially true if you extend the scenario to many friends or iteratively update posteriors.
One way to mitigate this is to work in log-space: instead of working with probabilities directly, you compute log-probabilities and add them when you would normally multiply. For example, log((2/3)^3) = 3 * log(2/3), which is more numerically stable than multiplying several small numbers. In Python, you might use math.log to handle log-domain computations. If you do not take such precautions, you risk floating-point errors that could skew your posterior probability.
How could external confirmation or data be incorporated?
You might have a weather forecast from a reputable source (e.g., a meteorological service) that says the probability of rain is 60%. That can be used to refine your prior probability or even serve as an additional “friend” with a high reliability. Alternatively, you might check a live webcam of Seattle. Each independent source can be incorporated via Bayesian updating, adjusting your belief after seeing each piece of evidence.
However, dependence can again creep in: if your friends are all quoting the same public weather forecast, their statements are not truly independent observations. The more correlated the sources, the less total “new information” you gain from each one.
How would the scenario evolve if you learned post-factum that one friend was definitely lying this time?
If, after receiving the unanimous yes responses, you learn that friend #2 was definitely lying (for instance, you discover a social media post saying they played a practical joke), you need to condition your posterior on that new piece of information. In Bayesian terms, you are adding an additional event: friend #2 is known to have lied. This changes the probability distribution because the friend #2 “Yes” is no longer a standard 2/3–1/3 scenario; it becomes a guaranteed lie.
Thus, your updated probability of it raining would consider (i) friend #2’s known “no” stance on truth, (ii) friend #1’s “Yes,” and (iii) friend #3’s “Yes” in the normal sense. The formula updates accordingly. A pitfall is failing to recalculate from the start with this new piece of data or incorrectly mixing old and new probabilities without adjusting the model.