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.
Cet exercice fait partie du cours
Foundations of Probability in Python
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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)