CommencerCommencer gratuitement

Tossing a coin

In the video, you have seen our custom get_heads_prob() function that estimates the probability of success of a binomial distribution. In this exercise, you will use it yourself and verify whether it does its job well in a coin-flipping experiment.

Watch out for the confusion: there are two different probability distributions involved! One is the binomial, which we use to model the coin-flipping. It's a discrete distribution with two possible values (heads or tails) parametrized with the probability of success (tossing heads). The Bayesian estimate of this parameter is another, continuous probability distribution. We don't know what kind of distribution it is, but we can estimate it with get_heads_prob() and visualize it.

numpy and seaborn have been imported for you as np and sns, respectively.

Cet exercice fait partie du cours

Bayesian Data Analysis in Python

Afficher le cours

Instructions

  • Generate a list of 1000 coin tosses (0s and 1s) with 50% chance of tossing heads, and assign to the variable tosses.
  • Use the tosses and the get_heads_prob() function to estimate the heads probability, and assign the result to heads_prob.
  • Draw a density plot of the distribution of the heads probability you have just estimated.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Generate 1000 coin tosses
tosses = ____(____, ____, ____)

# Estimate the heads probability
heads_prob = ____

# Plot the distribution of heads probability
____(____, shade=True, label="heads probabilty")
plt.show()
Modifier et exécuter le code