IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Practicing Statistics Interview Questions in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Generate some data for the distribution using the rvs() function with size set to 1000; assign it to the data 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.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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(____)
Modifica ed esegui il codice