In the first section we introduced the concept of empirical probability as the relative frecuency of a given outcome.
Now that we know how to calculate some theoretical probabilities, let's perform some experiments and compare them!
Remember the last experiment of throwing a dice $5$ times. We calculated the probability of getting all ones as
p_all_ones = (1/6) ** 5 p_all_ones
Now, let's model this experiment, and see what the relative frequency is:
def throw_dice(): return [random.randint(1,6) for _ in range(5)]
[1, 3, 5, 1, 5]
Given $n$ throws, let's count how many are all ones.
def count_all_ones(n): amount_found = 0 for _ in range(n): dice = throw_dice() if dice == [1,1,1,1,1]: amount_found += 1 return amount_found
def prob(n): return count_all_ones(n)/n
We can see that the empirical probability gets closer to the theoretical probability as we throw the dice more times.