Exercise

Sampling from a geometric distribution

Eva has a biased coin that has a probability of turning heads only 20% of the time. Eva flips her coin and records the number of flips needed to get a result of heads.

The geometric distribution is perfectly suited to model the number of flips needed to reach a result of heads, with the success rate p defined as the probability of turning heads each time.

Your task is to use the geometric distribution to simulate Eva's coin flips to reach heads 10,000 times, recording the number of flips needed to reach heads each time. Then, you'll visualize the results!

The following have been imported for you: seaborn as sns, pandas as pd, SciPy's stats module as st, and matplotlib.pyplot as plt.

Instructions

100 XP
  • Set p to the appropriate probability of success, where success is defined as flipping heads.
  • Using p as the probability of success, sample from the geometric distribution st.geom 10,000 times.