Preview

A lesson from Essential Probability & Statistics for ML

£29/month

£29/month£29/month or £249/year · 30-day money-back guarantee

Get full access

Our content is best on a larger screen

The law of large numbers

The law of large numbers

Explanation

The law of large numbers is one of the central results of probability. It is the reason an expected value means something in practice: the average of many independent repetitions of a random quantity converges to its expected value μ\mu.

A casino cannot predict the result of one spin of a roulette wheel, but it can predict its takings over a million spins. It relies on the law of large numbers, which states precisely what this convergence means.

The law of large numbers

Theorem

Let X1,X2,X3,…X_1, X_2, X_3, \ldots be i.i.d. random variables, each with finite mean μ\mu, and let Xˉn\bar X_n be the average of the first nn:

Xˉn=X1+⋯+Xnn\bar X_n = \dfrac{X_1 + \cdots + X_n}{n}

Then for every margin ε>0\varepsilon > 0,

lim⁡n→∞P(∣Xˉn−μ∣>ε)=0\lim\limits_{n \to \infty} P\big(\lvert \bar X_n - \mu \rvert > \varepsilon\big) = 0

Here ∣Xˉn−μ∣>ε\lvert \bar X_n - \mu \rvert > \varepsilon says that the average is more than ε\varepsilon away from μ\mu, and the limit says that the probability of this tends to 00 as nn grows.

We say that the average converges to μ\mu. This is a statement about a probability. It does not say that Xˉn\bar X_n ever equals μ\mu, or that it is sure to be within ε\varepsilon of μ\mu once nn is large.

12345678910123456
n
Xn
μ=3.5

Step 1: Rolling a die

A fair die shows 1 to 6, each with probability 16, so one roll has mean μ=3.5, marked by the dashed line.

The dots are the first 10 rolls of one run of rolls: X1=4, X2=1, X3=6, and so on. Each dot sits at the number rolled.

Step 2: The running average

After each roll, we take the average of all the rolls so far. After 3 rolls, for example,

X¯3=4+1+63≈3.67

The blue line joins these averages, from X¯1=4 to X¯10=3.8.

Step 3: Many more rolls

We keep rolling, up to n=2000. The vertical axis now shows only 2.5 to 4.5, so that we can see the band 3.5±0.1.

The running average varies widely over the first rolls, then less and less. It is outside the band for long stretches, but by n=2000 it is inside it.

Step 4: Rolling again

Each new run of rolls gives a different line. All of them come close to 3.5, but at a given n some can still be outside the band.

So the law cannot say where one run will be. It says that the probability of a run being outside the band tends to 0 as n grows.

Intuition

Tip

When each term has finite variance σ2\sigma^2, the variance of Xˉn\bar X_n is σ2n\dfrac{\sigma^2}{n}, which tends to 00 as nn grows. So the distribution of Xˉn\bar X_n is concentrated more and more tightly around μ\mu, and the probability that Xˉn\bar X_n is more than ε\varepsilon from μ\mu tends to 00.

ML Context

To evaluate a machine learning model, we measure its error on each example in a test set (examples the model was not trained on). If the examples are independent draws from the distribution the model will be used on, these errors are i.i.d., with mean μ\mu equal to the model's expected error on a new example. Their average, the test error, is Xˉn\bar X_n, so by the law of large numbers it converges to μ\mu as the test set grows.

Practice questions

5 questions

The numbers of customers who arrive at a shop in different minutes are i.i.d., each with mean 44. Let Xˉn\bar X_n be the average number of arrivals over the first nn minutes.

What does the law of large numbers say about Xˉn\bar X_n?

Select the correct answer:

+ 4 more questions · unlocked with a subscription

Expected proportions after an early run

Explanation

In 1913, at the casino in Monte Carlo, a roulette ball landed on black 2626 times in a row. As the run went on, gamblers lost millions of francs betting that red was due: they had misread the law of large numbers as saying that luck evens out.

To see why this is wrong, we simplify the roulette wheel: with no green pocket, each spin lands on black with probability 12\dfrac{1}{2}. If we record each spin as 11 for black and 00 for red, the proportion of blacks is their average, so by the law of large numbers it converges to 12\dfrac{1}{2}.

Now suppose the first 1010 spins give 99 blacks. The later spins are independent of these, so they are still expected to split evenly. For example, the next 9090 spins are expected to give 12×90=45\dfrac{1}{2} \times 90 = 45 blacks, so 9+45=549 + 45 = 54 in all after 100100 spins.

SpinsBlacks so far + expected from later spinsExtra blacks over an even splitExpected proportion of blacks
10109+0=99 + 0 = 99−5=49 - 5 = 40.90.9
1001009+45=549 + 45 = 5454−50=454 - 50 = 40.540.54
100010009+495=5049 + 495 = 504504−500=4504 - 500 = 40.5040.504

Key Point

The 44 extra blacks are never cancelled: they stay in the count. But their share of a growing number of spins shrinks towards 00, so the proportion still converges to 12\dfrac{1}{2}. We say the early lead is diluted. The same holds however long the early run, even 100100 blacks in a row.

What if the wheel might not be fair?

Details

Example

A fair coin lands heads 88 times in the first 1010 tosses. Find the probability of heads on toss 1111 and the expected proportion of heads after 10001000 tosses.

Solution

The tosses are independent, so the first 1010 do not change toss 1111, and the condition can be dropped:

P(heads on toss 11∣8 heads in the first 10)=P(heads on toss 11)=12\begin{align*} P(\text{heads on toss } 11 \mid 8 \text{ heads in the first } 10) &= P(\text{heads on toss } 11) \\[6pt] &= \dfrac{1}{2} \end{align*}

For the proportion, the first 1010 tosses are known, and 1000−10=9901000 - 10 = 990 tosses are still to come. Let YY be the number of heads among them. Each of these tosses lands heads with probability 12\dfrac{1}{2}, so by linearity of expectation

E[Y]=990×12=495\mathbb{E}[Y] = 990 \times \dfrac{1}{2} = 495

The number of heads in all 10001000 tosses is 8+Y8 + Y, with expected value 8+495=5038 + 495 = 503, so the expected proportion of heads is

5031000=0.503\dfrac{503}{1000} = 0.503

Practice questions

4 questions

A fair die shows a six on each of its first 55 rolls. What is the probability that roll 66 shows a six?

Select the correct answer:

+ 3 more questions · unlocked with a subscription

Memory is built by recalling, not by reading.

Every time you pull an answer from memory, the memory gets stronger. Reading doesn't do that. Nodeledge asks you questions on every step of every lesson, then asks again after days, weeks and months.

Get full access

£29/month or £249/year · 30-day money-back guarantee

See the learning path