Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scipy.stats as stats
- # Using Cumulative function as a faster way to calculate than pmf
- # probability of observing 3 or fewer heads from 10 fair coin flips
- # P(3 or fewer heads)=P(0 to 3 heads)
- prob_1 = stats.binom.cdf(3, 10, 0.5)
- print(prob_1)
- # compare to pmf code - add each from 0 to 3
- print(stats.binom.pmf(0, n=10, p=.5) + stats.binom.pmf(1, n=10, p=.5) + stats.binom.pmf(2, n=10, p=.5) + stats.binom.pmf(3, n=10, p=.5))
- # probability of observing more than 5 heads from 10 fair coin flips (use 1 minus) - want from 6 to 10
- # P(more than 5 heads)= 1 − P(5 or fewer heads)
- prob_2 = 1- stats.binom.cdf(5, 10, 0.5)
- print(prob_2)
- # probability of observing between 2 and 5 heads from 10 fair coin flips
- # P(2 to 5 Heads)=P(0 to 5 Heads)−P(0 to 1 Heads)
- prob_3 = stats.binom.cdf(5, 10, 0.5) - stats.binom.cdf(1, 10, 0.5)
- print(prob_3)
- # compare to pmf code - add each from 2 to 5
- print(stats.binom.pmf(2, n=10, p=.5) + stats.binom.pmf(3, n=10, p=.5) + stats.binom.pmf(4, n=10, p=.5) + stats.binom.pmf(5, n=10, p=.5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement