Binomial distribution
As we touched on in the slides, the binomial distribution is used to model the number of successful outcomes in trials where there is some consistent probability of success.
For this exercise, consider a game where you are trying to make a ball in a basket. You are given 10 shots and you know that you have an 80% chance of making a given shot. To simplify things, assume each shot is an independent event.
Cet exercice fait partie du cours
Practicing Statistics Interview Questions in Python
Instructions
- Generate some data for the distribution using the
rvs()
function with size set to 1000; assign it to thedata
variable. - Display a
matplotlib
histogram; examine the shape of the distribution. - Assign the probability of making 8 or less shots to
prob1
and print the result. - Assign the probability of making all 10 shots to
prob2
and print the result.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Generate binomial data
from scipy.stats import binom
data = binom.rvs(n=____, p=____, size=____)
# Plot the distribution
plt.hist(____)
plt.show()
# Assign and print probability of 8 or less successes
prob1 = binom.cdf(k=____, n=____, p=____)
print(____)
# Assign and print probability of all 10 successes
prob2 = binom.pmf(k=____, n=____, p=____)
print(____)