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
.
Cet exercice fait partie du cours
Foundations of Probability in Python
Instructions
- Import
geom
fromscipy.stats
,matplotlib.pyplot
asplt
, andseaborn
assns
. - Generate a sample with
size=10000
from a geometric distribution with a probability of success of 0.3. - Plot the sample generated.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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()