Syllabus Lesson 30 of 246 · Module 2: Maths and probability, only as needed
Module 2: Maths and probability, only as needed

Chance, averages and spread

Why it matters Training data is random samples, weights start random, and a classifier outputs probabilities. You need just enough probability to read those numbers.

See it

Roll a fair die many times. Each face comes up about 1 time in 6. The average of the faces settles near 3.5, even though you can never roll a 3.5. That settling value is the expected value: the long-run average.

A bigger sample gives an average closer to 3.5. With 10 rolls you might see 2.9 or 4.1; with 10,000 rolls you will see something like 3.49 or 3.51. Remember this: a number measured on a few examples wobbles; on many, it settles.

Probability: the long-run share of times something happens. Expected value: the long-run average, the sum of each outcome times its probability.

Recap Averages settle as the sample grows. Small samples lie a little.

Words and symbols in this lesson
expected value (E[x])
the long-run average
Your turn

Write expected_value(outcomes, probs) (sum of outcome times probability), and simulate_mean(n, seed) that rolls a fair die n times with np.random.default_rng(seed).integers(1, 7, size=n) and returns the average.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.