ML Interview Q Series: Calculating Event Count Probabilities Using the Poisson Distribution
Browse all the Probability Interview Questions here.
Events which occur randomly at rate r are counted over a time period of length s so the event count X is Poisson. Find P(X=2), P(X<2) and P(X>2) when (a) r=0.8, s=1; (b) r=0.1, s=8; (c) r=0.01, s=200; (d) r=0.05, s=200.
Short Compact solution
For (a) r=0.8, s=1 and (b) r=0.1, s=8, the product r·s=0.8. Hence the mean of the Poisson distribution λ=0.8.
P(X=2) = e^(-0.8)*(0.8^2 / 2)=0.1438
P(X<2)=P(X=0)+P(X=1)=0.4493+0.3695=0.8088
P(X>2)=1−0.8088−0.1438=0.0474
For (c) r=0.01, s=200, the mean λ=2.
P(X=2)=0.2707
P(X<2)=0.4060
P(X>2)=0.3233
For (d) r=0.05, s=200, the mean λ=10.
P(X=2)=0.00227
P(X<2)=0.00050
P(X>2)=0.9972
Comprehensive Explanation
The number of events X happening in a time interval of length s, when the events occur at a constant average rate r, is often modeled by a Poisson distribution. The Poisson distribution has a single parameter λ, which is the mean number of events in the interval. In this scenario, λ = r·s.
The defining probability mass function for the Poisson distribution is:
where k is a nonnegative integer representing the number of occurrences, λ is the average number of occurrences in that interval, e is the base of the natural logarithm, and k! is the factorial of k.
Below is a detailed breakdown of each probability the question asks for:
P(X=2): This is the probability of observing exactly 2 events. To compute this, you substitute k=2 into the Poisson formula. In plain text, P(X=2) = (λ^2 * e^(-λ)) / 2!.
P(X<2): This is the cumulative probability of observing fewer than 2 events, meaning k=0 or k=1. In plain text, P(X<2) = P(X=0) + P(X=1).
P(X>2): This is 1 minus the probability of having 2 or fewer events. In plain text, P(X>2) = 1 - (P(X=0) + P(X=1) + P(X=2)).
To see how λ changes for each sub-question:
(a) r=0.8, s=1 => λ=0.8
(b) r=0.1, s=8 => λ=0.8
(c) r=0.01, s=200 => λ=2
(d) r=0.05, s=200 => λ=10
Then, plugging into the Poisson formula and summing up relevant probabilities gives us the numerical results shown in the Short Compact solution.
Practical Computation Notes
Evaluating factorial terms and exponentials accurately is crucial to avoid floating-point issues. For larger λ or k, direct factorial computations can overflow. In most practical programming libraries, functions such as
scipy.stats.poisson
(in Python) or specialized routines in R can be used to compute Poisson probabilities accurately.When λ is large (e.g., λ=10), P(X=2) can be quite small. On the other hand, P(X>2) might be very large in such a case.
Python Code Snippet Example
import math
def poisson_pmf(k, lambd):
return (lambd**k * math.exp(-lambd)) / math.factorial(k)
# Example for lambda=0.8
l = 0.8
p_x_eq_2 = poisson_pmf(2, l)
p_x_lt_2 = poisson_pmf(0, l) + poisson_pmf(1, l)
p_x_gt_2 = 1 - (p_x_lt_2 + p_x_eq_2)
print("P(X=2):", p_x_eq_2)
print("P(X<2):", p_x_lt_2)
print("P(X>2):", p_x_gt_2)
This snippet demonstrates how to compute P(X=2), P(X<2), and P(X>2) for λ=0.8. You can repeat the same approach for other λ values.
What if the rate r is not constant?
In real-world problems, the event rate r might vary over time instead of being a fixed constant. In such cases, the basic Poisson assumption (which requires a constant rate) no longer holds. One might need to use a nonhomogeneous Poisson process where λ is integrated over the time interval:
If r(t) denotes the instantaneous rate at time t, then we define λ=∫[0 to s] r(t) dt.
Each sub-interval might have a different rate. The final Poisson parameter λ becomes the integral of that time-varying rate. In practice, you would discretize the time interval, sum up the small contributions, and then treat the combined total as your effective λ.
How to interpret P(X>2) in a more general sense?
One might often want to find P(X>k) for a general k. We can write:
P(X>k) = 1 − (P(X=0) + P(X=1) + ... + P(X=k)).
For computational efficiency, especially when k is not too large, summing the individual probabilities is easy. However, if k is large, many libraries provide cumulative distribution functions (CDFs) to handle these calculations in a single call without having to sum many terms by hand.
Could we use normal or other approximations for large λ?
When λ is sufficiently large (typically above 10), a normal approximation to the Poisson can be useful:
X ~ Poisson(λ) can be approximated by a normal distribution N(λ, λ).
Though not exact, it can simplify calculations if exact Poisson evaluations become cumbersome. One would also add continuity corrections for improved accuracy when using the normal approximation in discrete scenarios. This can be helpful in production code if performance is an issue, but for small to moderate λ, the direct Poisson formula or standard library routines are typically more exact.
What if we need confidence intervals for the Poisson parameter?
Sometimes interviewers extend the discussion to interval estimation. Suppose we observe x events in a time interval of length s, and we want to estimate r (the underlying rate). The Poisson parameter would be λ_estimated = x / 1 for the same interval length if s=1 or x / s in general. To get a confidence interval for the true rate r, we can use known approaches for Poisson confidence intervals (like the Clopper-Pearson interval in a binomial setting or specific methods for Poisson). This can be important in practical applications where we want to bound the uncertainty around r.
Real-World Edge Cases
If the observation time s is extremely large and r is small (e.g., r=0.001, s=1,000,000), λ might be large, and direct factorial calculations can overflow. Approximate methods or library functions become essential.
If s is very small, P(X>2) might be negligible or close to zero, but not strictly zero. Floating-point precision can become an issue.
If r changes over time or depends on conditions (like user visits in a website context that may differ by time of day), a piecewise Poisson or a more sophisticated model might be required.
All these discussions help demonstrate a deep understanding of the Poisson distribution and related practical concerns that might arise in a FANG-level interview setting.