FAQ: More on Probability Distributions - Calculating Probabilities of a Range using the Cumulative Density Function

This community-built FAQ covers the “Calculating Probabilities of a Range using the Cumulative Density Function” exercise from the lesson “More on Probability Distributions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Master Statistics with Python

Probability

FAQs on the exercise Calculating Probabilities of a Range using the Cumulative Density Function

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I think I found a problem with either the lesson or the checkpoint test.

The instructions note that when we are trying to calculate the CDF for a ‘specific number or more given the expected value of the distribution,’ such as calculating the probability of observing 12 or more rain events in the next 30 days when we expect 10, we would do the following:

import scipy.stats as stats
# expected value = 10, probability of observing 12 or more
1 - stats.poisson.cdf(11, 10)

The value of 11 is noted because we are including 12 and our statement evaluates the probability of observing 1 - (11 or fewer rain events).

This makes sense.

However, when we get to Checkpoint 1, we get a similar problem, where we are instructed to calculate the CDF of more than 20 calls when 15 are expected.

Seems easy enough, where we can just repeat the code from the lesson:
prob_more_than_20 = 1 - stats.poisson.cdf(19, 15)

However, the checkpoint test counts this as wrong and the test only passes if you use the value of 20:
prob_more_than_20 = 1 - stats.poisson.cdf(20, 15)

Shouldn’t the value of this parameter be 19 and not 20? Is the checkpoint test wrong, or am I missing something?

Notice:
probability that it’s 20 or more would be P(X ≥ 20) = 1 − P(X < 20) = 1 − P(X ≤ 19)
so that’s = 1 - stats.poisson.cdf(19, mean_rate)
[because the complement of 20 or more occurrences is 19 or less occurrences].

However,
probability that it’s more than 20 would be P(X > 20) = 1 − P(X ≤ 20)
which is = 1 - stats.poisson.cdf(20, mean_rate)
[because the complement of 21 or more occurrences is 20 or less occurrences].

The first includes 20, the second does not.

extra details

Note that it works this way because the Poisson distribution is discrete
(here, you can have 20 or 21 occurrences, but nothing between those).
So, P(X > 20) = P(X ≥ 21) and P(X < 20) = P(X ≤ 19)
But that would not be the case for a continuous distribution,
where you’d have
P(X > 20) = P(X ≥ 20) and P(X < 20) = P(X ≤ 20)

1 Like