Aan de slagGa gratis aan de slag

Generating and plotting geometric distributions

In sports it is common for players to make multiple attempts to score points for themselves or their teams. Each single attempt can have two possible outcomes, scoring or not scoring. Those situations can be modeled with geometric distributions. With scipy.stats you can generate samples using the rvs() function for each distribution.

Consider the previous example of a basketball player who scores free throws with a probability of 0.3. Generate a sample, and plot it.

numpy has been imported for you with the standard alias np.

Deze oefening maakt deel uit van de cursus

Foundations of Probability in Python

Cursus bekijken

Oefeninstructies

  • Import geom from scipy.stats, matplotlib.pyplot as plt, and seaborn as sns.
  • Generate a sample with size=10000 from a geometric distribution with a probability of success of 0.3.
  • Plot the sample generated.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import geom, matplotlib.pyplot, and seaborn
from ____
import ____
import ____

# Create the sample
sample = ____.____(p=____, size=10000, random_state=13)

# Plot the sample
sns.____(sample, bins = np.linspace(0,20,21), kde=False)
plt.show()
Code bewerken en uitvoeren