Measuring a sample
Let's work with a sample of coin flips to calculate some probabilities. You will calculate absolute and relative frequency and check the theoretical value from the distribution of the sample data.
The array sample_of_two_coin_flips
has 1,000 experiments, each consisting of two fair coin flips. For each experiment, we record the number of heads out of the two coin flips: 0, 1, or 2.
We've preloaded the binom
object and the find_repeats()
and relfreq()
methods from the scipy.stats
library for you. You'll need these to calculate the probabilities in this exercise.
This exercise is part of the course
Foundations of Probability in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Count how many times you got 2 heads from the sample data
count_2_heads = ____(sample_of_two_coin_flips).counts[2]
# Divide the number of heads by the total number of draws
prob_2_heads = count_2_heads / ____
# Display the result
print(prob_2_heads)