This community-built FAQ covers the “Using the Cumulative Distribution Function in Python” exercise from the lesson “Introduction to Probability Distributions”.
Paths and Courses
This exercise can be found in the following Codecademy content:
FAQs on the exercise Using the Cumulative Distribution Function in Python
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 () 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 () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Why does the cdf show a slightly different output compared to the summed up pmf function while calculating the same probabilities? Shouldn’t they be the same?
I think that’s just a limitation of floating point numbers and operations on them won’t give you perfect accuracy to an unlimited number of decimal places because there’s only a finite amount of space used to store the numbers.
(Calculating the cdf may also use different code than just the sum of the pmf internally.)
Although they’re both about 0.6123046875; that seems close enough.
I just figured I should add this since it’s bugging me and perhaps anyone who reads this may find it useful. The exercise makes out like it is much harder to use the pmf for calculating the probability x falls within some range, but actually, I find it easier because you can simplify it by using the range() function and the .sum() method:
Suppose we want to calculate the probability that we observe between 2 and 7 heads. Using the cdf, we would write:
I think checkpoint 3 on this one is wrong. If you want to calculate the probability of flipping 5 or more heads. You’d want to subtract from 1, the probability of flipping 0 to 4 heads which would be stats.binom.cdf(4, 10, 0.5). The answer that they claimed is correct in 1 - stats.binom.cdf(5, 10, 0.5) is actually calculating the probability of flipping 6 or more heads. Am I crazy?