Deviation from the Mean · Law of Large Numbers
Lesson 5
Let’s illustrate this with an example: perform the experiment \(10^{4}\) times, which ends in success with probability \(\frac{1}{3}\), and observe how the value of \(\beta\), the average number of successes, behaves. As can be seen, with increasing \(n\), it clusters more tightly around its mean.
import matplotlib.pyplot as plt
from random import seed, randint
seed(17)
n = 10 ** 4
trials = [1 if randint(0, 2) == 0 else 0 for _ in range(n)]
average = [sum(trials[:i]) / i for i in range(1, n)]
for k in [30, 100, 1000, 10000]:
plt.clf()
plt.plot(average[:k])
plt.savefig(f'average{k}.png')