Exercise

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.

Instructions

100 XP
  • 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.