← back to EEE 485
Week 1155 min full read
7 concepts26 worked examples32 exercises4 exam-level7 figures
What are you here for?

01 Introduction and probability review for machine learning

Start with this

One question before you read anything. Getting it wrong is the point: it shows you what this section is for.

§01.0 — what a flag from a good filter is worth

An email filter catches 99 of every 100 spam emails and wrongly flags 1 of every 100 normal emails. In this inbox, 1 email in 100 is spam. An email has just been flagged.

Find(a) Roughly how likely is it that the flagged email is spam?
Given
  • the filter flags 99 of every 100 spam emails

  • it flags 1 of every 100 normal emails

  • 1 email in 100 is spam

Hint 1/4

Nothing needs to be remembered from a course. Imagine a large batch of emails and ask which of the flagged ones are spam.

Hint 2/4

Share of spam among flagged emails $=\dfrac{\text{flagged spam}}{\text{flagged spam} + \text{flagged normal}}$.

Hint 3/4

Take 10,000 emails. Spam: 100, and 99 of them are flagged. Normal: 9,900, and 1 in 100 of them, so 99, are flagged.

Hint 4/4

So 99 of the 198 flagged emails are spam, and the answer is about 0.50.

Show solution

Counting a concrete batch is faster than recalling a formula, and it shows the one number people forget: how many normal emails are flagged.

Split the batch

$$10{,}000\times 0.01 = 100 \text{ spam},\quad 9{,}900 \text{ normal}$$

a batch of 10,000 turns 1 in 100 into whole emails

$$100\times 0.99 = 99,\qquad 9{,}900\times 0.01 = 99$$

the two flag rates applied to their own groups

Keep only the flagged emails

$$\frac{99}{99 + 99} = \frac{99}{198} = 0.50$$

given a flag, the batch shrinks to the 198 flagged emails

Answer $$\boxed{P(\text{spam}\mid\text{flag}) = 0.50}$$
Check

Formula route: $\frac{0.99\times 0.01}{0.99\times 0.01 + 0.01\times 0.99} = \frac12$. The two terms are equal because the rare class and the error rate are both 1 in 100.

Here the false alarm rate equals the share of spam, so false flags match true ones one for one. Keep the base rate in view whenever you read a flag.

A face recognition model is tried on 400 photos it never saw in training and gets 36 wrong, 9 in every 100. A manager asks: could it really miss 14 in every 100 on the next million photos, and how many test photos would pin the true rate down to within 2 in every 100?

By the end of this section you can say how far a measured test error can sit from the true one and how many test samples a promise needs, using the probability underneath: and , and their , , densities and the .

In 60 seconds

A learning algorithm is judged on data it has not seen, so this section rebuilds the probability behind every such judgement and ends with Hoeffding's inequality, which turns a measured test error into a guarantee about the true one.

Bayes' rule with total probability
$$P(A\mid B) = \frac{P(B\mid A)\,P(A)}{\sum_i P(B\mid A_i)\,P(A_i)}$$

you know how likely the evidence is under each hypothesis and want the hypothesis given the evidence

Indicators and variance
$$E[I(X\in A)] = P(X\in A),\qquad \operatorname{Var}(aX+b) = a^2\operatorname{Var}(X)$$

a probability or a count has to become an average; a quantity is rescaled or shifted

Covariance matrix
$$\Sigma = E\big[(X-\mu)(X-\mu)^T\big],\qquad \operatorname{Var}(a^TX) = a^T\Sigma a \ge 0$$

several features at once; the variance of any weighted sum of them

Hoeffding and the sample size
$$P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le 2e^{-2n\varepsilon^2},\qquad n\ge\frac{\ln(2/\delta)}{2\varepsilon^2}$$

independent terms in [0, 1], such as error indicators on a that was not used for training

Three most common mistakes
  1. Reading $P(\text{flag}\mid\text{fraud})$ as $P(\text{fraud}\mid\text{flag})$. A detector that catches 99 of 100 frauds can still be wrong about most of the transactions it flags, when fraud is rare.

  2. Treating zero covariance as independence. Covariance only sees a straight-line trend, so $Y = X^2$ can have zero covariance with $X$ while depending on it completely.

  3. Using Hoeffding's inequality outside its conditions: variables not rescaled to [0, 1], the factor 2 dropped, the sample size rounded down, or the training set used as if it were a test set.

The weights differ between two course documents:

  • Chapter 1 slides, undergraduate line: midterm 25, final 25, four quizzes 20, two-phase project 30, out of 100 points.
  • STARS syllabus page printed on 21 September 2026: midterm 30, final 30, problem sets and quizzes 20, project 20. It is the later document; confirm in the first weeks which split applies.
  • To sit the final, both require every project report on time, no disciplinary penalty, and midterm plus quiz points worth at least a fifth of those two components.
How much time do you have?
10 minutes

Bayes' rule with its denominator, and Hoeffding's inequality turned into a test-set size: the two calculations this chapter builds towards.

The 60-second card · Conditional probability, independence and Bayes' rule · Averages settle down · Formula card
45 minutes

Every calculation in the section once: event probabilities and bounds, conditionals, distributions, means and variances, covariance matrices and sample sizes.

The 60-second card · Probability spaces · Conditional probability, independence and Bayes' rule · Random variables and their distributions · Expectation, variance and the indicator trick · Several random variables at once · Averages settle down · Scaffolding comes off · B · computation
full read

Adds the machine learning frame the probability serves: what an algorithm learns from, why training error misleads, and why a guarantee needs a separate test set.

The opening pages · Learning from data · Probability spaces · Conditional probability, independence and Bayes' rule · Random variables and their distributions · Expectation, variance and the indicator trick · Several random variables at once · Averages settle down · Method boxes · Look-alike pairs · Scaffolding comes off · Full exam-style question · Practice set · Check yourself
By the end of this section
  1. Describe a learning problem as $Y = f(X) + \omega$: name the inputs, , and goal, and tell supervised, unsupervised and apart from the data alone.

  2. Build the probability space of a small experiment, compute event probabilities from the axioms, and bound the probability of a union when the overlaps are unknown.

  3. Compute conditional probabilities, test two events for independence, and reverse a conditional with Bayes' rule and the .

  4. Move between the CDF, pmf and pdf of a random variable, and pick the Bernoulli, , , Gaussian or beta model that fits a situation.

  5. Calculate expectations and variances from a pmf or pdf, using linearity and indicator variables to avoid long sums.

  6. Analyse several random variables together: , conditionals, covariance, and the mean vector and covariance matrix of a random vector, including the Gaussian case.

  7. Bound the gap between a sample average and its mean with Hoeffding's inequality, and find the test-set size a given tolerance and failure chance require.

Syllabus coverage

Introduction — covered

Goals and tools of learning from data: the model Y = f(X) + ω, training data, the goal of doing well on unseen data, and the three kinds of learning

The lecturer's chapter opens with this overview before any probability, and so does this section.

Probability review for machine learning and data science — covered

Probability spaces and the three axioms, the order property, the union bound, and the frequentist and Bayesian readings of a probability

The two readings of probability get one short table here; the inference methods built on them belong to the next section.

random variables — covered

  • CDF, pmf and pdf
  • the Bernoulli, binomial, Poisson, Gaussian and beta families
  • expectation, variance and

Split over two concepts: distributions first, then expectation and variance.

random vectors — covered

  • Joint and marginal distributions
  • and Bayes' rule for random variables
  • covariance
  • the mean vector and covariance matrix
  • the density

Bayes rule — covered

Conditional probability, Bayes' rule for events with the law of total probability in the denominator, and Bayes' rule for random variables with a pmf or a density as the

The version for random variables is worked in the concept on several random variables, where conditional distributions are defined.

independence — covered

  • Independent events
  • independent random variables
  • the factorisation E[g(X)h(Y)] = E[g(X)]E[h(Y)] for independent X and Y
  • identically distributed and i.i.d. samples
  • why zero covariance is weaker than independence

Events are handled with Bayes' rule; random variables, i.i.d. samples and covariance come back in the concept on several random variables.

law of large numbers — covered

Averages of i.i.d. samples settle at the mean, and the gives the scale and bell shape of the remaining error

The central limit theorem is not named in the official line, but it sits next to the law of large numbers in the lecturer's chapter, so it is covered here.

concentration inequalities — covered

Hoeffding's inequality for independent variables in [0, 1], applied to the error rate of a fixed on a test set, and solved for the test-set size

Hoeffding's inequality is the one on the lecture slides. Chebyshev's inequality appears once, in an example marked further reading, only as a yardstick for how much Hoeffding saves.

Credible and confidence intervals — deferred

Turning data into statements about an unknown parameter, the Bayesian and the frequentist way

Deferred to the next section, Bayesian and frequentist machine learning, which has its own week. Nothing here builds an interval for a parameter; Hoeffding is used only as a bound on the chance of a large miss.

Recall first
Set operations

For events $A, B\subseteq\Omega$: $A\cup B$ is 'either', $A\cap B$ is 'both', $A^c$ is 'not $A$', and $B\setminus A = B\cap A^c$. Disjoint means $A\cap B = \varnothing$. De Morgan: $(A\cup B)^c = A^c\cap B^c$.

Events are sets. The complement trick, 'at least one' equals one minus 'none', is used in several examples.

Counting

$\binom{n}{k} = \frac{n!}{k!\,(n-k)!}$ counts the ways to choose which $k$ of $n$ positions are successes, and a string of $n$ two-way choices has $2^n$ possibilities.

The binomial pmf and the of small experiments.

The exponential series

$e^{\lambda} = \sum_{k=0}^{\infty}\lambda^k/k!$, and $(1-\lambda/n)^n\to e^{-\lambda}$ as $n\to\infty$.

The first makes the Poisson pmf add up to 1; the second is where the comes from.

Integrals of powers

$\int_0^1 s^k\,ds = \frac{1}{k+1}$ for $k\ge 0$.

Every continuous expectation in this section reduces to integrals of this kind.

Two by two matrices

For $M = \begin{bmatrix}a & b\\ c & d\end{bmatrix}$: $\det M = ad - bc$ and $M^{-1} = \frac{1}{ad-bc}\begin{bmatrix}d & -b\\ -c & a\end{bmatrix}$. For a column vector $v$, $v^TMv$ is a number, and $(AB)^T = B^TA^T$.

Covariance matrices, the test and the Gaussian density in two dimensions.

Logarithms

For $\delta > 0$: $2e^{-x}\le\delta$ exactly when $x\ge\ln(2/\delta)$, where $\ln$ is the natural logarithm.

Solving Hoeffding's bound for the number of samples.

Standard normal tail values

For $Z\sim N(0,1)$: $P(\vert Z\vert\ge 1) = 0.317$, $P(\vert Z\vert\ge 1.96) = 0.050$ and $P(\vert Z\vert\ge 2) = 0.0455$.

The central limit theorem examples read their probabilities from these three values.

Try it yourself first (2 questions)
1§01.0 — does a streak make the other side due

A fair coin has landed tails five times in a row. A friend says the law of large numbers pushes the share of heads towards one half, so heads is now more likely than tails on the next toss.

Find(a) True or false: heads is now more likely than tails on the next toss.
Given
  • fair coin

  • tosses are independent

  • the last five tosses were tails

Hint 1/4

Separate what the law says about long-run averages from what it says about any single toss.

Hint 2/4

Independence: $P(\text{heads next}\mid\text{any past}) = P(\text{heads next})$.

Hint 3/4

For a fair coin that is $\tfrac12$, whatever the five earlier tosses showed.

Hint 4/4

So the claim is false: the next toss is heads with probability $\tfrac12$.

Show solution

Use independence directly; arguing from the long-run average is exactly the trap the question sets.

Condition on the past

$$P(H_6\mid T_1T_2T_3T_4T_5) = \frac{P(H_6\cap T_1\cdots T_5)}{P(T_1\cdots T_5)}$$

definition of conditional probability

$$= \frac{(1/2)^6}{(1/2)^5} = \frac12$$

independent tosses multiply

Answer $$\boxed{P(\text{heads next}) = \tfrac12:\ \text{false}}$$
Check

Symmetry check: the sequences TTTTTH and TTTTTT have the same probability, $(1/2)^6$ each, so neither ending is favoured.

Averages converge by dilution, not by compensation. No finite streak changes the next independent toss.

2§01.0 — is the mean always a possible value

A fair six-sided die is rolled once and $X$ is the number shown. Someone claims that the expected value of a random variable is always one of the values it can take, since it is the outcome we 'expect'.

Find(a) True or false: for this die, $E[X]$ is a value that no single roll can show.
Given$X$ is equally likely to be $1, 2, 3, 4, 5$ or $6$
Hint 1/4

Test the claim on the die instead of arguing in general.

Hint 2/4

$E[X] = \sum_x x\,p_X(x)$.

Hint 3/4

Here $p_X(x) = \tfrac16$ for $x = 1,\dots,6$, so $E[X] = \frac{1+2+3+4+5+6}{6}$.

Hint 4/4

So $E[X] = 3.5$, which no roll can show: the statement is true, and the claim that the mean is always a possible value fails.

Show solution

A single counterexample settles a claim about 'every random variable', so compute one case.

Weighted sum

$$E[X] = \tfrac16(1+2+3+4+5+6) = \tfrac{21}{6} = 3.5$$

each face weighted by its probability

Answer $$\boxed{E[X] = 3.5 \notin \{1,\dots,6\}:\ \text{true}}$$
Check

Symmetry check: the faces pair up as 1 and 6, 2 and 5, 3 and 4, and every pair averages 3.5, so the balance point must be 3.5.

Read an expectation as a long-run average: over many rolls the average face is 3.5, even though no single roll is.

Notation
symbolreads asmeanswatch out
$\Omega,\ \mathcal F,\ P$

omega, script F, P

the sample space, the collection of events we may ask about, and the

for a finite $\Omega$ the events are simply all subsets, written $2^{\Omega}$

$\omega$

omega (lower case)

a single outcome in $\Omega$, and also the in $Y = f(X) + \omega$

the course uses the same letter for both; the context always tells you which one is meant

$P(A\mid B)$

P of A given B

the chance of A once B is known to have happened

not the same number as $P(B\mid A)$; swapping them is the most common error in this section

$F_X(x)$

the CDF of X at x

$P(X\le x)$, climbing from 0 to 1

the $\le$ includes $x$ itself, which matters at the jumps of a discrete variable

$p_X(x),\ f_X(x)$

the pmf, the pdf

$P(X = x)$ for a discrete $X$; the slope of $F_X$ for a continuous $X$

a pdf value is a density, not a probability, and it may be larger than 1

$E[X],\ \operatorname{Var}(X)$

expectation of X, variance of X

the probability-weighted average, and the average squared distance from it

$E[X^2]$ and $(E[X])^2$ are different numbers; their gap is the variance

$I(X\in A)$

the indicator of the event

1 when $X\in A$ happens, 0 otherwise

it is itself a random variable, with mean $P(X\in A)$

$X\sim N(\mu,\sigma^2)$

X is Gaussian with mean mu and variance sigma squared

a bell-shaped density centred at the mean

the second entry is the variance: $N(0,4)$ has standard deviation 2

$\operatorname{Cov}(X,Y),\ \Sigma$

covariance of X and Y, capital sigma

how two variables move together; the matrix of all pairwise covariances of a random vector

$\Sigma$ here is a matrix, not a sum sign

$\bar X_n,\ \bar Z$

X bar n, Z bar

the average of $n$ samples, $\frac1n\sum_{i=1}^n X_i$

it is random: a new sample gives a new average

$R(f),\ \hat R_n(f)$

the risk of f, R hat n of f

the true error rate $P(f(X)\ne Y)$, and the error rate measured on $n$ test pairs

$R(f)$ is a fixed unknown number; $\hat R_n(f)$ is a random estimate of it

$\hat f$

f hat

the rule an algorithm outputs after seeing the training data

it depends on the training data, which is why it cannot be tested on them

Conventions used here
Conditioning needs a positive denominator.

We write $P(A\mid B)$ only when $P(B) > 0$, and $p_{Y\mid X}(y\mid x)$ only where $p_X(x) > 0$.

Otherwise the definition divides by zero, and the ways of patching that case are not needed in this course.

Densities are not probabilities.

For a continuous $X$, $P(X = x) = 0$ for every $x$, so $P(X\le x) = P(X<x)$, and a pdf value may exceed 1. For a discrete $X$, $\le$ and $<$ can differ by a whole jump.

Most CDF and pdf errors come from carrying a habit from one case into the other.

Gaussian parameters.

$N(\mu,\sigma^2)$ lists the mean and the variance, as the course slides do; $N(0,4)$ has standard deviation 2.

Some software takes the standard deviation instead, and a variance typed where a standard deviation belongs moves every tail probability.

Logarithms.

$\ln$ is the natural logarithm and $\exp(x) = e^{x}$; the sample-size formula $n\ge\ln(2/\delta)/(2\varepsilon^2)$ uses $\ln$.

Using $\log_{10}$ there gives a sample size too small by a factor of about 2.3.

Vectors are columns.

$X = [X_1,\dots,X_n]^T$ is a column, $x^T$ is a row and $\Sigma$ is $n\times n$, so $(x-\mu)^T\Sigma^{-1}(x-\mu)$ is a single number.

Writing the product in the other order produces an n by n matrix where the density needs a number.

Sample sizes round up.

A sample size from an inequality $n\ge c$ is rounded up to the next whole number, even when $c$ sits just above an integer.

Rounding down gives an n for which the promised bound is not quite reached.

Counts instead of percentages.

Probabilities are turned into counts in an imagined population, such as 99 of every 100 frauds or 1,998 false alarms in 100,000 transactions. These are expected counts, not observed data.

Conditional probabilities are easier to get right as counts, and counts make the denominator of Bayes' rule visible.

Three words for 'unrelated'.

Independent random variables have a joint CDF that factorises for every pair of values; , or i.i.d., adds that they share one distribution; only means zero covariance.

The words are often used loosely, and the gap between the first and the last is exactly where a counterexample in this section lives.

1.1Learning from data: the model Y = f(X) + ω and three kinds of learning

Fixes what an algorithm learns from, what it is judged on, and why that judgement is a question about probability.

Before any probability we need the object this course studies: a rule built from a finite list of examples and then used on examples nobody has seen yet.

Solvable with what we have
  • Count how many of 1,000 stored training emails a filter labels wrongly.

  • Store every training email with its label and look it up again.

  • Report which label is more common in the training set.

Not solvable yet
  • Say how the filter will do on tomorrow's emails, which it has never seen.

  • Say how far a measured error rate can sit from the true one.

  • Decide how many test emails are enough to trust a reported error.

The obvious report judges the filter on the emails it was built from. A filter that memorises all 1,000 training emails, and answers 'not spam' for anything it has not stored, makes 0 mistakes on them. So the report says: error 0 out of 1,000.

Why it fails

The memoriser has a table, not a rule. Almost every new email is missing from the table, so it always answers 'not spam' and is wrong on every spam email. Zero training mistakes measured memory, not learning.

DefinitionThe setup
Conditions
  • each example is a pair $(x_i, y_i)$: an input $x_i$, such as an email, an image or a list of measurements, and its label $y_i$

  • the pairs come from the same source that will later produce the inputs we care about

  • $\omega$ is noise, the part of the label that no function of the input can predict

$$\boxed{\begin{aligned} &\text{model:} && Y = \textcolor{#d1690a}{f}(X) + \textcolor{#6f42c1}{\omega}\\ &\text{data:} && \textcolor{#1f6feb}{(x_i, y_i)},\quad i = 1,\dots,n\\ &\text{learning:} && (x_1,y_1),\dots,(x_n,y_n)\ \longrightarrow\ \text{algorithm}\ \longrightarrow\ \hat f\\ &\text{goal:} && \hat f(X)\approx Y \ \text{ for new pairs } (X,Y)\end{aligned}}$$

The label is an unknown function of the input plus noise. We see $n$ labelled examples, an algorithm turns them into an estimate $\hat f$, and $\hat f$ is judged on new pairs from the same source, not on how well it repeats the $n$ examples it was given.

Looks like this, but is not

A table of 5,000 customers with a column 'left the service: yes or no', and the task of spotting which customers will leave. It sounds like finding groups without a teacher, which is how is usually described.

The 'left' column is a label $Y$ for every row, and the real goal is $\hat f(X)\approx Y$ for new customers. That is supervised learning, a classification task. Unsupervised learning starts from inputs with no label column at all.

kindwhat the data look likewhat is learnedexamples

supervised

pairs $(x_i, y_i)$

a rule $\hat f$ with $\hat f(X)\approx Y$

sales from advertising budgets; handwritten digits; ship silhouettes

unsupervised

inputs $x_i$ only

structure: groups, a shorter description, hidden sources

grouping pixels to compress an image; separating mixed recordings

reinforcement

actions, and rewards that follow them

a way of choosing actions that earns reward

recommenders that learn from clicks; robots learning to walk

Decide from the data, not the goal: a label column means supervised, no labels means unsupervised, and rewards that depend on your own actions mean reinforcement.

Error of a memorising spam filter on new email

A filter stores all 1,000 of its training emails with their labels. For a stored email it returns the stored label; for any other email it answers 'not spam'. In the stream of new emails, 30 of every 100 are spam, and no new email is an exact copy of a stored one.

FindThe share of mistakes on the training emails and on new emails.
Given
  • 1,000 stored training emails, each answered with its own label

  • any unstored email is answered 'not spam'

  • 30 of every 100 new emails are spam

  • no new email repeats a stored one

Solution

Count mistakes per 100 emails instead of reasoning about the filter in general: its behaviour on new mail is fixed completely by its rule, so a count settles it.

Training emails

$$\text{mistakes} = 0 \text{ of } 1{,}000$$

every training email is in the table and gets its own label back

$$\text{training error} = 0$$

0 divided by 1,000

New emails

$$\text{answer} = \text{not spam for every new email}$$

no new email is in the table, so the default answer is always the one used

$$\text{mistakes} = 30 \text{ of every } 100$$

the answer is wrong exactly on the spam emails, and there are 30 in every 100

$$\text{error on new email} = 0.30$$

30 divided by 100

Answer $$\boxed{\text{training error } 0,\qquad \text{error on new email } 0.30}$$
Check

A rule that never looked at any data, 'always answer not spam', also makes 30 mistakes in every 100 new emails. The memoriser does exactly as well as a rule that learned nothing.

That settles the report from the start of this concept: the 0 was about memory, the 0.30 is about learning. Every error this course cares about is measured on examples the algorithm did not train on.

Supervised, unsupervised or reinforcement: three tasks sorted

Classify each task.

  • (i) Predict the selling price of a flat from its size, age and district, using 3,000 past sales.
  • (ii) Split 50,000 news articles into topics when no article carries a topic tag.
  • (iii) A thermostat changes the heating and, an hour later, receives a comfort score from the occupants.
FindThe kind of learning in each task.
Given
  • (i) 3,000 past sales with their prices

  • (ii) 50,000 untagged articles

  • (iii) heating actions, each followed by a comfort score

Solution

Ask two questions in a fixed order, 'is there a label for each example?' and then 'do the learner's own actions decide what it sees next?', instead of judging from the application area.

Look for a label

$$\text{(i)}:\ (x_i, y_i) = (\text{size, age, district};\ \text{price})$$

each past sale comes with its price, so there is a label to predict

$$\text{(ii)}:\ x_i = \text{article, and no } y_i$$

no article carries a topic, so there is nothing to predict against

Look for actions and rewards

$$\text{(iii)}:\ \text{action}\ \to\ \text{reward}$$

the score arrives after the thermostat acts, and a different setting would have earned a different score

Name them

$$\text{(i) supervised},\ \ \text{(ii) unsupervised},\ \ \text{(iii) reinforcement}$$

label present; label absent; reward that depends on the learner's own action

Answer $$\boxed{\text{(i) supervised}\quad \text{(ii) unsupervised}\quad \text{(iii) reinforcement}}$$
Check

Test (iii) against the supervised reading: nobody ever tells the thermostat the right setting, only how good its chosen setting was, so there is no label to fit.

Sort by the data, not by the domain: the same flats would be an unsupervised task if the prices were missing.

Checkpoint
§01.1 — which kind of learning a music app does

A music app plays one song after another. After each song it records whether the listener skipped it, and it uses those records to choose the next songs.

Find(a) Which kind of learning describes the app's task best?
Given
  • the app picks every song itself

  • after each pick it sees 'skipped' or 'not skipped'

Hint 1/4

Do not start from the word 'data'. Ask who decides which song gets a reaction recorded.

Hint 2/4

Supervised: labelled pairs given in advance. Unsupervised: inputs only. Reinforcement: the learner acts and then receives a reward that depends on its action.

Hint 3/4

In this app, the app chooses every song, and afterwards it sees only 'skipped' or 'not skipped' for that song, never which song it should have chosen.

Hint 4/4

So the task is reinforcement learning.

Show solution

Apply the two questions from the worked example: is there a label, and do actions decide the feedback?

Is there a label?

$$\text{skip} \ne \text{the right song}$$

a skip scores the chosen song; it never says which song was correct

Do actions decide the feedback?

$$\text{song chosen}\ \to\ \text{skip or not}\ \to\ \text{next choice}$$

the app only learns about songs it decided to play

Answer $$\boxed{\text{reinforcement learning}}$$
Check

Contrast check: if the app were handed a fixed file of songs, each with the song the listener preferred, it would be supervised. Nothing like that file exists here.

When the learner's actions decide what data it gets, it is doing reinforcement learning, whatever the domain.

⚠ Reporting training error as the performance

it is the only error you can compute without holding data back, and a small number looks like good news

wrong$$\text{training error} = 0\ \Rightarrow\ \text{error on new data}\approx 0$$
right$$\text{error on new data is measured on examples not used for training}$$
⚠ Expecting the right rule to pass through every training point

fitting the data exactly feels like the goal of learning

wrong$$\hat f(x_i) = y_i \ \text{for all } i \ \text{is the aim}$$
right$$y_i = f(x_i) + \omega_i:\ \text{even } \hat f = f \text{ misses by } \omega_i$$

1.2Probability spaces: outcomes, events and three axioms

Assigns a probability to every event from three rules, and gives the order property and the union bound for free.

The error of a learner is a probability, so first we say exactly what a probability is attached to; for coin tosses this machinery looks like overkill, and it is, until the events get complicated.

DefinitionProbability space (Ω, F, P)
Conditions
  • $\Omega$, the sample space, is the set of all outcomes of the experiment

  • $\mathcal F$ holds the events, the subsets of $\Omega$ we may ask about; for a finite $\Omega$ it is every subset, the power set $2^{\Omega}$

  • $P$ gives each event a number and obeys the three axioms (A1) to (A3)

$$\boxed{\begin{aligned} &\text{(A1)}\ \ P(A)\ge 0 \ \text{ for every } A\in\mathcal F\\ &\text{(A2)}\ \ P(\Omega) = 1\\ &\text{(A3)}\ \ P\Big(\bigcup_i A_i\Big) = \sum_i P(A_i)\ \text{ if } A_i\cap A_j = \varnothing,\ i\ne j\\ &\text{order:}\ \ A\subseteq B\ \Rightarrow\ P(A)\le P(B)\\ &\text{union bound:}\ \ P\Big(\bigcup_i A_i\Big)\le\sum_i P(A_i)\end{aligned}}$$

Probabilities are never negative, the whole space has probability one, and for events that cannot happen together the chance that one happens is the sum. So an event is never more likely than a larger event containing it, and the chance of at least one of several events is at most the sum of their chances.

Proof

Order. Let $C = B\setminus A$, the part of $B$ outside $A$. Then $A$ and $C$ are disjoint and $A\cup C = B$.

By (A3), $P(B) = P(A) + P(C)$, and by (A1), $P(C)\ge 0$, so $P(B)\ge P(A)$.

Union bound, two events. $A\cup B$ is the disjoint union of $A$ and $B\setminus A$, so $P(A\cup B) = P(A) + P(B\setminus A)$.

The order property gives $P(B\setminus A)\le P(B)$, hence $P(A\cup B)\le P(A) + P(B)$. Adding one event at a time extends this to any number of events.

Looks like this, but is not

A spam model reports $P(\text{spam}) = 0.6$ and $P(\text{not spam}) = 0.5$ for an email. Each number lies between 0 and 1, so each one looks like a legitimate probability.

The two events are disjoint and together make up the whole sample space, so (A2) and (A3) force the two numbers to add up to 1. Here they add up to 1.1, so no probability space produces this pair.

readingwhat $P(\text{heads}) = \tfrac12$ sayswhat it describes

frequentist

in 1,000 tosses, about 500 heads, with the share settling near one half as tosses continue

a long run of repeatable experiments

Bayesian

before the next toss, heads and tails are equally plausible to me

my uncertainty about one event

Both readings obey the same three axioms, so every rule in this section holds under either. They part ways when the unknown is a parameter instead of an event, which is the subject of the next section.

Sample space of a three-image mini-batch

A mini-batch takes 3 images one after another. Each draw is a cat (C) or a dog (D) with equal chance, independently of the other draws. Build the probability space and find the chance of at least one dog, of exactly two cats, and of a cat first.

Find$\Omega$, $P$, and the three probabilities.
Given
  • 3 draws

  • each draw is C or D with chance 1/2

  • the draws are independent

Solution

List ordered outcomes like CCD instead of counts like 'two cats': ordered outcomes are equally likely and counts are not, and counting only works for equally likely outcomes.

Build the space

$$\Omega = \{CCC, CCD, CDC, DCC, CDD, DCD, DDC, DDD\}$$

3 positions with 2 options each give 2 cubed, so 8, ordered outcomes

$$P(\{\omega\}) = \tfrac18 \ \text{ for each } \omega$$

independent fair draws make every ordered string equally likely

$$P(A) = \frac{\vert A\vert}{8}$$

by (A3), any event is the sum of its equal single-outcome pieces

At least one dog

$$A^c = \{CCC\}\ \Rightarrow\ P(A) = 1 - \tfrac18 = \tfrac78$$

the complement 'no dog' is a single outcome, quicker than listing seven

Two cats, and a cat first

$$\{CCD, CDC, DCC\}\ \Rightarrow\ \tfrac38$$

the one dog can sit in any of the 3 positions

$$\{CCC, CCD, CDC, CDD\}\ \Rightarrow\ \tfrac48 = \tfrac12$$

the first letter is fixed as C and the other two are free

Answer $$\boxed{P(\text{at least one dog}) = \tfrac78,\quad P(\text{two cats}) = \tfrac38,\quad P(\text{cat first}) = \tfrac12}$$
Check

Sum check: 0, 1, 2 and 3 cats have chances 1/8, 3/8, 3/8 and 1/8, which add to 1 as (A2) demands. Giving the four counts a quarter each would put 'exactly two cats' at 1/4.

Count only equally likely outcomes. When a natural description, like the number of cats, has unequal chances, go down to the ordered outcomes first.

Bracketing a failure chance with two free properties

A prediction service calls three components on every request. Their failure chances are 0.02, 0.03 and 0.01, and nothing is known about how the failures are related. The request fails if any component fails. What can be said for sure about the chance that a request fails?

FindUpper and lower bounds on $P(A_1\cup A_2\cup A_3)$.
Given
  • $P(A_1) = 0.02$, $P(A_2) = 0.03$, $P(A_3) = 0.01$

  • the request fails on $A_1\cup A_2\cup A_3$

  • no information about dependence

Solution

Use the two properties instead of an exact formula: the exact union needs the overlaps, which are unknown, while the bounds need only the three numbers.

Upper bound

$$P(A_1\cup A_2\cup A_3)\le 0.02 + 0.03 + 0.01 = 0.06$$

the union bound holds whatever the overlaps are

Lower bound

$$A_2\subseteq A_1\cup A_2\cup A_3\ \Rightarrow\ P(\text{fail})\ge 0.03$$

the order property, applied to the most likely single failure

Together

$$0.03\le P(\text{fail})\le 0.06$$

neither bound assumed anything about how failures are related

Answer $$\boxed{0.03\le P(\text{request fails})\le 0.06}$$
Check

If the failures happened to be independent, the exact value would be $1 - 0.98\times 0.97\times 0.99 = 0.0589$. It sits inside the bracket, near the top because the overlaps are tiny.

When dependence is unknown, bound instead of guessing. The union bound is how a single guarantee can later cover many error events at once.

Checkpoint
§01.2 — three screening rules and the union bound

Three screening rules each wrongly block a normal email with probability at most 0.01. An email is blocked if any rule blocks it, and nothing is known about how the rules' mistakes are related.

Find(a) What can you say for sure about the chance that a normal email is wrongly blocked?
Given
  • each rule wrongly blocks a normal email with probability at most 0.01

  • blocked if any of the three rules blocks it

  • no information about dependence

Hint 1/4

The event of interest is 'at least one rule blocks', a union of three events whose overlaps are unknown.

Hint 2/4

Union bound: $P(A_1\cup A_2\cup A_3)\le P(A_1) + P(A_2) + P(A_3)$, with no condition on dependence.

Hint 3/4

Each $P(A_i)\le 0.01$, so the sum is at most $0.01 + 0.01 + 0.01$.

Hint 4/4

So the chance is at most 0.03, and nothing sharper follows from what is given.

Show solution

Only the union bound can be used, because an exact value would need the overlaps.

Apply the union bound

$$P(A_1\cup A_2\cup A_3)\le\sum_{i=1}^{3}P(A_i)\le 3\times 0.01 = 0.03$$

holds for any overlaps, including none

Answer $$\boxed{P(\text{wrongly blocked})\le 0.03}$$
Check

The bound is reached when the three mistakes never happen together and each has chance exactly 0.01, so 0.03 cannot be improved without more information.

The union bound is sharp when the events barely overlap, which is the usual situation for rare errors.

⚠ Counting unequal outcomes as if they were equally likely

'number of cats' has four values, and it is tempting to give each value a quarter

wrong$$P(\text{exactly two cats}) = \tfrac14$$
right$$P(\text{exactly two cats}) = \tfrac38$$
⚠ Adding the chances of events that overlap

(A3) looks like a general rule for unions, but it only applies to disjoint events

wrong$$P(A\cup B) = P(A) + P(B)$$
right$$P(A\cup B) = P(A) + P(B) - P(A\cap B)\le P(A) + P(B)$$

1.3Conditional probability, independence and Bayes' rule

Updates a probability once evidence arrives, and turns 'data given hypothesis' into 'hypothesis given data'.

So far every probability was measured against all of $\Omega$; evidence means we learn that an event $B$ happened, and $B$ becomes the new whole.

TheoremConditioning, independence and Bayes' rule
Conditions
  • $P(B) > 0$, so that dividing by it makes sense

  • in the denominator, $A_1,\dots,A_k$ split $\Omega$: they are disjoint and one of them always happens

$$\boxed{\begin{aligned} P(A\mid B) &= \frac{P(A\cap B)}{P(B)}\\ A, B \text{ independent} &\iff P(A\cap B) = P(A)\,P(B)\\ P(A\mid B) &= \frac{P(B\mid A)\,P(A)}{P(B)},\qquad P(B) = \sum_{i=1}^{k}P(B\mid A_i)\,P(A_i)\end{aligned}}$$

Given B, the chance of A is the share of B that also lies in A. Independence means this share equals the plain chance of A, so one event says nothing about the other. Bayes' rule reverses the conditioning: the is proportional to the times the likelihood, the chance of the evidence under the hypothesis.

Proof

The definition gives $P(A\cap B) = P(A\mid B)\,P(B)$ and, with the roles swapped, $P(A\cap B) = P(B\mid A)\,P(A)$.

Set the two equal and divide by $P(B)$: that is Bayes' rule.

For the denominator, $B$ is the disjoint union of the pieces $B\cap A_i$, so (A3) gives $P(B) = \sum_i P(B\cap A_i) = \sum_i P(B\mid A_i)P(A_i)$, the law of total probability.

Looks like this, but is not

Two events that can never happen together look like the least related pair there is: 'the image is a cat' and 'the image is a dog', each with probability 0.5.

They are strongly dependent. If one happens the other cannot, so $P(\text{cat}\cap\text{dog}) = 0$ while $P(\text{cat})\,P(\text{dog}) = 0.25$. Independence means one event says nothing about the other; here it says everything.

clickeddid not clicktotal

mobile

90

510

600

desktop

60

340

400

total

150

850

1,000

Both rows click at the same rate, $90/600 = 60/400 = 0.15$, the rate of the whole table. That is what independence looks like in a table of counts.

What a fraud flag means: 99 hits in 100, and 1 fraud in 1,000

A detector flags 99 of every 100 fraudulent transactions and 2 of every 100 legitimate ones. One transaction in 1,000 is fraudulent. A transaction has been flagged. How likely is it to be fraud?

Find$P(\text{fraud}\mid\text{flag})$
Given
  • $P(\text{fraud}) = 0.001$

  • $P(\text{flag}\mid\text{fraud}) = 0.99$

  • $P(\text{flag}\mid\text{legit}) = 0.02$

Solution

Count through an imagined population of 100,000 transactions before touching the formula: the counts make the denominator visible, and the denominator is where this problem is usually lost.

Split the population by the prior

$$100{,}000\times 0.001 = \textcolor{#1f6feb}{100}\ \text{fraud},\qquad 99{,}900\ \text{legitimate}$$

a round population turns 1 in 1,000 into whole transactions

Split each branch by its likelihood

$$100\times 0.99 = \textcolor{#1f6feb}{99}\ \text{flagged frauds}$$

the hit rate applies to the fraud branch only

$$99{,}900\times 0.02 = \textcolor{#1f6feb}{1{,}998}\ \text{false alarms}$$

the false alarm rate applies to the legitimate branch, which is a thousand times larger

Condition on the flag

$$P(\text{fraud}\mid\text{flag}) = \frac{99}{99 + 1{,}998} = \frac{99}{2{,}097}$$

given a flag, only the 2,097 flagged transactions remain, and 99 of them are fraud

$$= \textcolor{#d1690a}{0.0472}$$

one division

Answer $$\boxed{P(\text{fraud}\mid\text{flag})\approx 0.047}$$
Check

Formula route, without the counts: $P(\text{flag}) = 0.99(0.001) + 0.02(0.999) = 0.02097$ and $0.00099/0.02097 = 0.0472$. Sense check: among flags, false alarms outnumber frauds about 20 to 1, so the answer must be near 1/21.

Three multiplications and one division. Counting is slower than the formula the first time, and it is the version that still works under exam stress.

The flag is strong evidence, since it multiplies the odds by 0.99/0.02 = 49.5, but the odds start at 1 to 999. The prior matters as much as the detector.

Is clicking independent of the device? Reading it off a table

Out of 1,000 sessions, 600 were on mobile and 90 of those ended in a click; of the 400 desktop sessions, 60 ended in a click. Is the event 'click' independent of the event 'mobile'?

FindWhether $P(\text{click}\cap\text{mobile}) = P(\text{click})\,P(\text{mobile})$.
Given
  • 600 mobile sessions, 90 with a click

  • 400 desktop sessions, 60 with a click

Solution

Compare the conditional chance $P(\text{click}\mid\text{mobile})$ with $P(\text{click})$: it asks the same question as the product rule and reads straight off the table.

Unconditional and conditional chances

$$P(\text{click}) = \frac{90 + 60}{1{,}000} = 0.15$$

all clicks over all sessions

$$P(\text{click}\mid\text{mobile}) = \frac{90}{600} = 0.15$$

conditioning on mobile keeps only the 600 mobile sessions

Product check

$$P(\text{click}\cap\text{mobile}) = \frac{90}{1{,}000} = 0.09 = 0.15\times 0.6$$

the joint chance equals the product of the two separate chances

Answer $$\boxed{\text{independent: } P(\text{click}\mid\text{mobile}) = P(\text{click}) = 0.15}$$
Check

The desktop row must agree as well, and it does: $60/400 = 0.15$. With two rows, the overall rate is a weighted average of the two row rates, so if one row matches it, the other must too.

Independence is a numerical fact you check, not a story you assume: change 90 clicks to 120 and the same story becomes dependent.

Checkpoint
§01.3 — a flagged chip and Bayes' rule

A wafer test screens chips. 2 of every 100 chips are defective. The test flags 90 of every 100 defective chips and 5 of every 100 good chips.

Find(a) A chip is flagged. What is the probability that it is defective?
Given
  • $P(\text{defective}) = 0.02$

  • $P(\text{flag}\mid\text{defective}) = 0.90$

  • $P(\text{flag}\mid\text{good}) = 0.05$

Hint 1/4

The chip is known to be flagged, so the flagged chips are the new whole. Ask what share of them is defective.

Hint 2/4

Bayes: $P(D\mid F) = \dfrac{P(F\mid D)P(D)}{P(F\mid D)P(D) + P(F\mid G)P(G)}$.

Hint 3/4

With $P(D) = 0.02$, $P(F\mid D) = 0.90$ and $P(F\mid G) = 0.05$: the numerator is $0.90\times 0.02 = 0.018$ and the denominator is $0.018 + 0.05\times 0.98 = 0.067$.

Hint 4/4

So the chance is $0.018/0.067\approx 0.27$.

Show solution

The prior and both likelihoods are given, so Bayes' rule with total probability in the denominator is direct.

Evidence under each hypothesis

$$P(F\mid D)\,P(D) = 0.90\times 0.02 = 0.018$$

flagged and defective

$$P(F\mid G)\,P(G) = 0.05\times 0.98 = 0.049$$

flagged and good; the good chips are 98 in 100

Divide

$$P(D\mid F) = \frac{0.018}{0.018 + 0.049} = \frac{0.018}{0.067} = 0.269$$

the denominator is the total chance of a flag

Answer $$\boxed{P(\text{defective}\mid\text{flag})\approx 0.27}$$
Check

Counts in 1,000 chips: 20 defective give 18 flags, 980 good give 49 flags, and 18/67 = 0.269.

Whenever the bad class is rare, even a good test's false alarms can outnumber its true hits; always build the denominator from both branches.

⚠ Reading the conditional the wrong way round

the detector is described as 'flags 99 of 100 frauds', and that is the number in front of you

wrong$$P(\text{fraud}\mid\text{flag}) = P(\text{flag}\mid\text{fraud}) = 0.99$$
right$$P(\text{fraud}\mid\text{flag}) = \frac{0.99\times 0.001}{0.02097}\approx 0.047$$
⚠ Leaving the false alarms out of the denominator

the numerator is about fraud, so it feels natural to keep only fraud terms

wrong$$P(\text{flag}) = P(\text{flag}\mid\text{fraud})\,P(\text{fraud})$$
right$$P(\text{flag}) = 0.99(0.001) + 0.02(0.999) = 0.02097$$
⚠ Treating disjoint events as independent

'they have nothing to do with each other' sounds like independence

wrong$$A\cap B = \varnothing\ \Rightarrow\ P(A\cap B) = P(A)\,P(B)$$
right$$A\cap B = \varnothing,\ P(A), P(B) > 0\ \Rightarrow\ P(A\cap B) = 0\ne P(A)\,P(B)$$

1.4Random variables and their distributions: CDF, pmf, pdf and five named families

Turns outcomes into numbers, so probabilities become functions you can sum, integrate and plot.

Events answer yes or no questions, but a count of errors, a number of clicks or a sensor reading is a number, so we attach a number to every outcome.

DefinitionRandom variable, CDF, pmf and pdf
Conditions
  • a random variable is a function $X:\Omega\to\mathbb R$; the event $\{X\le x\}$ is the set of outcomes $\omega$ with $X(\omega)\le x$

  • discrete: $X$ takes finitely or countably many values; continuous: its CDF has a density

$$\boxed{\begin{aligned} F_X(x) &= P(X\le x)\\ p_X(x) &= P(X = x)\quad\text{(discrete)}\\ f_X(x) &= \frac{dF_X(x)}{dx}\quad\text{(continuous)}\\ P(X\in A) &= \sum_{x\in A}p_X(x)\ \ \text{or}\ \ \int_A f_X(x)\,dx\end{aligned}}$$

A random variable attaches a number to each outcome. Its CDF at x is the chance of a value at most x, climbing from 0 to 1. A discrete variable has a pmf, the chance of each value; a continuous one has a pdf, the slope of the CDF, and its probabilities are areas under that pdf.

Looks like this, but is not

A model's confidence score $S$ has density $f_S(s) = 2s$ on $[0,1]$, so $f_S(0.9) = 1.8$. A value above 1 looks like a probability above 1, so the density seems broken.

A density is probability per unit length, not a probability. Probabilities are areas: $P(0.9\le S\le 0.91)\approx 1.8\times 0.01 = 0.018$. Only the total area has to be 1, and $\int_0^1 2s\,ds = 1$.

familyvaluespmf or pdfa typical use in this course

Bernoulli $\mathrm{Ber}(p)$

$\{0,1\}$

$p_X(1) = p,\ p_X(0) = 1-p$

one prediction right or wrong; one click

binomial $\mathrm{Binomial}(n,p)$

$\{0,\dots,n\}$

$\binom{n}{y}p^{y}(1-p)^{n-y}$

errors among $n$ independent test cases

Poisson $\mathrm{Poisson}(\lambda)$

$\{0,1,2,\dots\}$

$e^{-\lambda}\lambda^{y}/y!$

rare events over many tries: failed requests, typos

Gaussian $N(\mu,\sigma^2)$

$\mathbb R$

$\frac{1}{\sqrt{2\pi\sigma^2}}e^{-(y-\mu)^2/(2\sigma^2)}$

the noise $\omega$ in $Y = f(X) + \omega$

beta $\mathrm{Beta}(\alpha,\beta)$

$[0,1]$

$\frac{1}{B(\alpha,\beta)}y^{\alpha-1}(1-y)^{\beta-1}$

an unknown proportion, such as a click rate

Read the family off the values the variable can take: 0 or 1 is Bernoulli, a count out of $n$ is binomial, an open-ended count of rare events is Poisson, any real number with a bell shape is Gaussian, and a number in $[0,1]$ is a candidate for a . $B(\alpha,\beta)$ is the constant that makes its area 1.

From outcomes to pmf and CDF: cats in a three-image batch

Three images are drawn independently, each a cat (C) or a dog (D) with chance 1/2. Let $X$ be the number of cats. Find the pmf and the CDF of $X$, and $P(1\le X\le 2)$.

Find$p_X$, $F_X$ and $P(1\le X\le 2)$.
Given
  • 8 equally likely ordered outcomes, from CCC to DDD

  • $X(\omega)$ is the number of C's in $\omega$

Solution

Group the 8 outcomes by their value of X first. The pmf is then a count, and the CDF is a running sum of the pmf, so no new probability has to be worked out.

pmf by grouping outcomes

$$X=0:\{DDD\},\ \ X=1:\{CDD, DCD, DDC\},\ \ X=2:\{CCD, CDC, DCC\},\ \ X=3:\{CCC\}$$

the random variable only relabels outcomes, so each value collects the outcomes mapped to it

$$p_X(0), p_X(1), p_X(2), p_X(3) = \tfrac18, \tfrac38, \tfrac38, \tfrac18$$

each outcome carries 1/8

CDF as a running sum

$$F_X(x) = 0,\ \tfrac18,\ \tfrac48,\ \tfrac78,\ 1\ \text{ on } x<0,\ [0,1),\ [1,2),\ [2,3),\ x\ge 3$$

the CDF adds the pmf of every value at or below x, and stays flat between values

An interval probability

$$P(1\le X\le 2) = F_X(2) - F_X(0) = \tfrac78 - \tfrac18 = \tfrac34$$

subtracting the CDF at 0, not at 1, keeps the value 1 inside the interval

Answer $$\boxed{p_X = \big(\tfrac18, \tfrac38, \tfrac38, \tfrac18\big),\qquad P(1\le X\le 2) = \tfrac34}$$
Check

Direct count: one or two cats covers 3 + 3 = 6 of the 8 outcomes, and 6/8 = 3/4. The CDF also ends at 1, as every CDF must.

For a discrete variable, subtract the CDF just below the left end of an interval, so that a jump sitting at the left end is kept.

A continuous confidence score with density 2s on [0, 1]

A classifier's confidence score $S$ has pdf $f_S(s) = 2s$ for $0\le s\le 1$ and 0 elsewhere. Check that this is a valid pdf, find the CDF, and find $P(S>0.5)$ and $P(S = 0.5)$.

FindThe CDF, $P(S>0.5)$ and $P(S = 0.5)$.
Given$f_S(s) = 2s$ on $[0,1]$, zero elsewhere
Solution

Find the CDF once and read every probability from it; integrating the pdf again for each question repeats the same work.

Validity

$$f_S(s)\ge 0,\qquad \int_0^1 2s\,ds = \big[s^2\big]_0^1 = 1$$

a pdf needs to be non-negative with total area 1; values above 1 are allowed

CDF

$$F_S(s) = \int_0^s 2t\,dt = s^2\quad (0\le s\le 1)$$

the CDF is the area to the left of s

Probabilities

$$P(S>0.5) = 1 - F_S(0.5) = 1 - 0.25 = 0.75$$

complement of 'at most 0.5'

$$P(S = 0.5) = 0$$

a continuous CDF has no jumps, so a single point carries no probability

Answer $$\boxed{F_S(s) = s^2,\qquad P(S>0.5) = 0.75,\qquad P(S = 0.5) = 0}$$
Check

Area route: under $2s$ between 0.5 and 1 lies a trapezoid with parallel sides 1 and 2 and width 0.5, of area $\frac{1+2}{2}\times 0.5 = 0.75$.

For continuous variables $\le$ and $<$ give the same probability; for discrete ones they may differ by a whole jump.

Law of rare events: 2,000 requests, each failing with chance 0.001

A server handles 2,000 requests, and each fails with probability 0.001, independently. Let $X$ be the number of failures. Find $P(X = 0)$ and $P(X\le 2)$ exactly, and with a Poisson approximation.

Find$P(X = 0)$ and $P(X\le 2)$, binomial and Poisson.
Given
  • $n = 2{,}000$ independent requests

  • failure chance $p = 0.001$ each

Solution

Compute the binomial once to see the exact answer, then the Poisson with the same mean $\lambda = np = 2$; the comparison is the point, since the Poisson needs no binomial coefficients with 2,000 in them.

Exact binomial

$$P(X = 0) = 0.999^{2000} = 0.13520$$

all 2,000 requests succeed

$$P(X\le 2) = \sum_{y=0}^{2}\binom{2000}{y}0.001^{y}\,0.999^{2000-y} = 0.67668$$

three terms: 0, 1 and 2 failures

Poisson with the same mean, 2

$$P(X = 0)\approx e^{-2} = 0.13534$$

Poisson pmf at 0

$$P(X\le 2)\approx e^{-2}\big(1 + 2 + \tfrac{2^2}{2}\big) = 5e^{-2} = 0.67668$$

the first three Poisson terms

Answer $$\boxed{P(X = 0)\approx 0.135,\qquad P(X\le 2)\approx 0.677\ \text{(both ways)}}$$
Check

The two values of P(X = 0), 0.13520 and 0.13534, agree to three decimals, and the two values of P(X ≤ 2) agree to seven. Mean check: both models have mean np = 2.

Many tries, each with a small chance, add up to a Poisson count with $\lambda = np$: the law of rare events. That is why counts of rare failures are modelled as Poisson.

Checkpoint
§01.4 — reading a pmf value off a CDF

A discrete random variable $X$ counts the defects found on a circuit board. Its CDF is $F_X(x) = 0$ for $x<0$, $0.2$ for $0\le x<1$, $0.7$ for $1\le x<3$, and $1$ for $x\ge 3$.

Find(a) Find $P(X = 1)$.
Given
  • $F_X(x) = 0$ for $x<0$

  • $F_X(x) = 0.2$ for $0\le x<1$

  • $F_X(x) = 0.7$ for $1\le x<3$

  • $F_X(x) = 1$ for $x\ge 3$

Hint 1/4

A pmf value of a discrete variable is visible on its CDF. Look at what the CDF does exactly at the value 1.

Hint 2/4

$P(X = x) = F_X(x) - F_X(x^-)$: the size of the jump at $x$, where $F_X(x^-)$ is the level just before $x$.

Hint 3/4

Here the CDF sits at 0.2 on $[0,1)$ and at 0.7 from $x = 1$, so the jump at 1 is $0.7 - 0.2$.

Hint 4/4

So $P(X = 1) = 0.5$.

Show solution

Subtract the level just before the value from the level at the value, which isolates exactly the probability sitting at that point.

Jump at 1

$$P(X = 1) = F_X(1) - F_X(1^-) = 0.7 - 0.2 = 0.5$$

the CDF includes 1 from the right and excludes it from the left

Answer $$\boxed{P(X = 1) = 0.5}$$
Check

Full pmf check: the jumps are 0.2 at 0, 0.5 at 1 and 0.3 at 3, which add to 1, and there is no jump at 2, so X never equals 2.

A discrete CDF is a staircase: the values are where it jumps and the probabilities are how high it jumps.

⚠ Reading a density value as a probability

both are written as a function of x and both get called 'the distribution'

wrong$$P(S = 0.9) = f_S(0.9) = 1.8$$
right$$P(S = 0.9) = 0,\qquad P(0.9\le S\le 0.91)\approx 0.018$$
⚠ Reading the level of a CDF as the pmf

the CDF is the function you were handed, and its value at 1 is right there

wrong$$P(X = 1) = F_X(1) = 0.7$$
right$$P(X = 1) = F_X(1) - F_X(1^-) = 0.7 - 0.2 = 0.5$$

1.5Expectation, variance and the indicator trick

Summarises a distribution by its balance point and its spread, and computes probabilities as averages of indicators.

A whole pmf is more than we usually need: learners are compared by one number, their average error, so we need the average of a random variable.

RuleExpectation, variance and indicators
Conditions
  • the sum or integral defining $E[g(X)]$ converges absolutely, so the mean is finite

  • linearity holds for any random variables, dependent or not

$$\boxed{\begin{aligned} E[g(X)] &= \sum_x g(x)\,p_X(x)\ \ \text{or}\ \ \int_{-\infty}^{\infty}g(y)\,f_X(y)\,dy\\ E[a\,g(X) + b\,h(Y)] &= a\,E[g(X)] + b\,E[h(Y)]\\ \operatorname{Var}(X) &= E\big[(X - E[X])^2\big] = E[X^2] - E[X]^2\\ \operatorname{Var}(aX + b) &= a^2\operatorname{Var}(X)\\ E[I(X\in A)] &= P(X\in A)\end{aligned}}$$

The expectation is the probability-weighted average of the values, the balance point of the pmf or pdf. It is linear, even for dependent variables. The variance is the average squared distance from the mean; a shift leaves it alone and scaling by $a$ multiplies it by $a^2$. An indicator averages to its event's probability.

Proof

Shortcut. With $\mu = E[X]$, expand the square and use linearity: $E[(X-\mu)^2] = E[X^2] - 2\mu E[X] + \mu^2 = E[X^2] - \mu^2$.

Scaling. $aX + b - E[aX + b] = a(X - \mu)$, so $\operatorname{Var}(aX + b) = E[a^2(X-\mu)^2] = a^2\operatorname{Var}(X)$; the shift $b$ cancels.

Indicator. $I(X\in A)$ is 1 with probability $P(X\in A)$ and 0 otherwise, so its mean is $1\cdot P(X\in A) + 0 = P(X\in A)$.

Looks like this, but is not

$E[X^2] = (E[X])^2$ looks like linearity applied to a square: the mean of the square equals the square of the mean.

Squaring is not linear. For the clicks per session below, $E[X^2] = 1.1$ while $(E[X])^2 = 0.49$. The gap, 0.61, is exactly the variance, and it is zero only when $X$ is a constant.

familymeanvariance

$\mathrm{Ber}(p)$

$p$

$p(1-p)$

$\mathrm{Binomial}(n,p)$

$np$

$np(1-p)$

$\mathrm{Poisson}(\lambda)$

$\lambda$

$\lambda$

$N(\mu,\sigma^2)$

$\mu$

$\sigma^2$

$\mathrm{Beta}(\alpha,\beta)$

$\frac{\alpha}{\alpha+\beta}$

$\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}$

Two quick checks are worth keeping: a Bernoulli variance $p(1-p)$ is never above $\tfrac14$, reached at $p = \tfrac12$, and a Poisson variable has variance equal to its mean.

Mean and variance of clicks per session

The number of clicks $X$ in a session has pmf $p_X(0) = 0.5$, $p_X(1) = 0.3$, $p_X(2) = 0.2$. Find $E[X]$ and $\operatorname{Var}(X)$.

Find$E[X]$ and $\operatorname{Var}(X)$.
Given$p_X(0) = 0.5$, $p_X(1) = 0.3$, $p_X(2) = 0.2$
Solution

Use the shortcut $E[X^2] - E[X]^2$: it needs one more weighted sum, while the definition needs three squared distances from a decimal mean.

Mean

$$E[X] = 0(0.5) + 1(0.3) + 2(0.2) = \textcolor{#d1690a}{0.7}$$

values weighted by their probabilities

Second moment

$$E[X^2] = 0(0.5) + 1(0.3) + 4(0.2) = 1.1$$

the same weighted sum with g(x) = x squared

Variance

$$\operatorname{Var}(X) = 1.1 - 0.7^2 = 0.61$$

shortcut formula from the box

Answer $$\boxed{E[X] = 0.7,\qquad \operatorname{Var}(X) = 0.61}$$
Check

Definition route: $(0-0.7)^2(0.5) + (1-0.7)^2(0.3) + (2-0.7)^2(0.2) = 0.245 + 0.027 + 0.338 = 0.61$.

An expectation is a balance point, not a typical value: nobody clicks 0.7 times.

Expected number of test errors through indicators

A classifier $f$ misclassifies a random test image with probability $R(f) = 0.09$. It is run on 400 test images drawn independently. Let $N$ be the number of errors. Find $E[N]$, and write $R(f)$ itself as an expectation.

Find$E[N]$, and $R(f)$ as an expectation.
Given
  • $R(f) = P(f(X)\ne Y) = 0.09$

  • 400 test pairs $(X_i, Y_i)$

Solution

Write N as a sum of 400 indicators. Linearity then gives the mean without the binomial pmf, and the argument would still work if the images were dependent.

A count is a sum of indicators

$$N = \sum_{i=1}^{400}I\big(f(X_i)\ne Y_i\big)$$

each term is 1 exactly when image i is misclassified

Mean of each indicator

$$E\big[I(f(X_i)\ne Y_i)\big] = P\big(f(X_i)\ne Y_i\big) = R(f) = 0.09$$

indicator rule from the box

Add

$$E[N] = 400\times 0.09 = 36$$

linearity; no independence needed

Answer $$\boxed{E[N] = 36,\qquad R(f) = E\big[I(f(X)\ne Y)\big]}$$
Check

Here $N$ is also $\mathrm{Binomial}(400, 0.09)$, and the binomial mean $np = 400\times 0.09 = 36$ agrees.

Any count is a sum of indicators, and any probability is the mean of an indicator. That is how a classifier's error rate becomes an average that data can estimate.

Mean and variance of the score with density 2s

The confidence score $S$ has pdf $f_S(s) = 2s$ on $[0,1]$. Find $E[S]$ and $\operatorname{Var}(S)$.

Find$E[S]$ and $\operatorname{Var}(S)$.
Given$f_S(s) = 2s$ on $[0,1]$
Solution

Same shortcut as in the discrete case, with integrals in place of sums; power-rule integrals make it quick.

Mean

$$E[S] = \int_0^1 s\cdot 2s\,ds = \tfrac23$$

the weight is the density

Second moment

$$E[S^2] = \int_0^1 s^2\cdot 2s\,ds = \tfrac24 = \tfrac12$$

power rule on 2s cubed

Variance

$$\operatorname{Var}(S) = \tfrac12 - \tfrac49 = \tfrac1{18}\approx 0.056$$

shortcut formula

Answer $$\boxed{E[S] = \tfrac23,\qquad \operatorname{Var}(S) = \tfrac1{18}}$$
Check

The density leans right, so the balance point must sit above the midpoint 1/2, and 2/3 does. The standard deviation $\sqrt{1/18}\approx 0.24$ is below 0.5, the largest any variable on $[0,1]$ can have.

Discrete or continuous, the recipe is the same: weight by the pmf or the pdf, then use the shortcut.

Checkpoint
§01.5 — variance after scaling and shifting

A sensor reading $X$ has variance 4. A preprocessing step replaces it by $3 - 2X$ before it is fed to a model.

Find(a) Find $\operatorname{Var}(3 - 2X)$.
Given
  • $\operatorname{Var}(X) = 4$

  • new feature $3 - 2X$

Hint 1/4

A shift moves every value by the same amount; a scale stretches the distances between values. Ask which of the two a variance can see.

Hint 2/4

$\operatorname{Var}(aX + b) = a^2\operatorname{Var}(X)$.

Hint 3/4

Here $a = -2$, $b = 3$ and $\operatorname{Var}(X) = 4$, so the variance is $(-2)^2\times 4$.

Hint 4/4

So $\operatorname{Var}(3 - 2X) = 16$.

Show solution

The scaling rule applies directly; expanding the definition would give the same result more slowly.

Apply the scaling rule

$$\operatorname{Var}(3 - 2X) = (-2)^2\operatorname{Var}(X)$$

the shift 3 cancels when the mean is subtracted

$$= 4\times 4 = 16$$

the square removes the minus sign

Answer $$\boxed{\operatorname{Var}(3 - 2X) = 16}$$
Check

Standard deviation check: the spread of $X$ is $\sqrt4 = 2$, doubling distances makes it 4, and $4^2 = 16$. A variance can never be negative, so $-8$ was impossible from the start.

Variance ignores shifts and squares scales; standard deviation ignores shifts and scales by the absolute value.

⚠ Squaring the mean instead of averaging the squares

for sums, 'take the mean' and the operation can be swapped, so it feels like they always can

wrong$$E[X^2] = (E[X])^2$$
right$$E[X^2] = \operatorname{Var}(X) + (E[X])^2$$
⚠ Scaling a variance by a, or letting a shift change it

the variance gets treated like the mean, which does pick up both a and b

wrong$$\operatorname{Var}(3 - 2X) = 3 - 2\operatorname{Var}(X)$$
right$$\operatorname{Var}(3 - 2X) = (-2)^2\operatorname{Var}(X) = 4\operatorname{Var}(X)$$

1.6Several random variables at once: joint laws, covariance and random vectors

Handles inputs with many coordinates: how variables move together, and the mean vector and covariance matrix of a random vector.

An input in machine learning is rarely one number; an image or a customer record is a list of numbers that vary together, so we need their , and the notation does get heavier from here.

DefinitionJoint laws, covariance and the covariance matrix
Conditions
  • conditionals are defined only where the conditioning marginal is positive, $p_X(x) > 0$

  • $g$ and $h$ are any functions whose expectations exist

  • $X = [X_1,\dots,X_n]^T$ is a column of random variables with finite variances and mean vector $\mu = E[X]$

  • for densities, pdfs replace pmfs, and an integral over the other variable replaces each sum

$$\boxed{\begin{aligned} p_{Y\mid X}(y\mid x) &= \frac{p_{XY}(x,y)}{p_X(x)},\qquad p_X(x) = \sum_y p_{XY}(x,y)\\ p_{Y\mid X}(y\mid x) &= \frac{p_{X\mid Y}(x\mid y)\,p_Y(y)}{\sum_{y'}p_{X\mid Y}(x\mid y')\,p_Y(y')}\\ X, Y \text{ independent} &\iff F_{XY}(x,y) = F_X(x)\,F_Y(y)\ \text{ for all } x, y\\ X, Y \text{ independent} &\Longrightarrow E[g(X)\,h(Y)] = E[g(X)]\,E[h(Y)],\ \text{ so } \operatorname{Cov}(X,Y) = 0\\ \operatorname{Cov}(X,Y) &= E\big[(X - E[X])(Y - E[Y])\big] = E[XY] - E[X]\,E[Y]\\ \Sigma &= E\big[(X-\mu)(X-\mu)^T\big],\qquad \Sigma_{ij} = \operatorname{Cov}(X_i, X_j)\\ f_X(x) &= \frac{1}{(2\pi)^{n/2}\vert\Sigma\vert^{1/2}}\exp\Big(-\tfrac12(x-\mu)^T\Sigma^{-1}(x-\mu)\Big)\end{aligned}}$$

A joint law gives chances for pairs of values; summing out one variable gives a marginal, and dividing by it gives a conditional. Independence factorises the joint CDF and the expectation of any product $g(X)h(Y)$, so the covariance is zero. The covariance matrix is symmetric and positive semidefinite, and with the mean it fixes a Gaussian vector completely.

Proof

Independence factorises expectations. For discrete variables independence means $p_{XY}(x,y) = p_X(x)\,p_Y(y)$, so $E[g(X)h(Y)] = \sum_x\sum_y g(x)h(y)\,p_X(x)\,p_Y(y)$.

The double sum splits into $\big(\sum_x g(x)p_X(x)\big)\big(\sum_y h(y)p_Y(y)\big) = E[g(X)]\,E[h(Y)]$. With $g(x) = x$ and $h(y) = y$ this gives $E[XY] = E[X]E[Y]$, so $\operatorname{Cov}(X,Y) = 0$.

Symmetric. $\Sigma_{ij} = \operatorname{Cov}(X_i, X_j) = \operatorname{Cov}(X_j, X_i) = \Sigma_{ji}$.

Positive semidefinite. Fix any vector $a$. The number $a^T(X-\mu)$ is a random variable with mean 0.

Its variance is $E\big[a^T(X-\mu)(X-\mu)^Ta\big] = a^T\Sigma a$, and a variance cannot be negative, so $a^T\Sigma a\ge 0$ for every $a$.

Looks like this, but is not

$X$ is $-1$, $0$ or $1$ with chance 1/3 each, and $Y = X^2$. Then $\operatorname{Cov}(X,Y) = E[X^3] - E[X]E[X^2] = 0 - 0 = 0$, so the two look unrelated.

$Y$ is a function of $X$, so knowing $X$ gives $Y$ exactly: $P(Y = 0\mid X = 0) = 1$ while $P(Y = 0) = 1/3$. Covariance only detects a straight-line trend, and this dependence is a parabola. Independence implies zero covariance, but not the other way round.

$X = 0$$X = 1$$X = 2$$p_Y(y)$

$Y = 0$, no recommendation

0.30

0.12

0.03

0.45

$Y = 1$, saw a recommendation

0.25

0.20

0.10

0.55

$p_X(x)$

0.55

0.32

0.13

1

Marginals are the row and column totals, and all six cells together add to 1. Each row divided by its own total is a conditional pmf of X.

Joint table: items bought and whether a recommendation was seen

For a random shop visit, $X$ is the number of items bought and $Y$ is 1 if the visitor saw a recommendation, 0 otherwise. Find the conditional pmf of $X$ given $Y = 1$, decide whether $X$ and $Y$ are independent, and compute $\operatorname{Cov}(X,Y)$.

Find$p_{X\mid Y}(x\mid 1)$, independence, and $\operatorname{Cov}(X,Y)$.
Given
  • $p_{XY}(0,0) = 0.30,\ p_{XY}(1,0) = 0.12,\ p_{XY}(2,0) = 0.03$

  • $p_{XY}(0,1) = 0.25,\ p_{XY}(1,1) = 0.20,\ p_{XY}(2,1) = 0.10$

Solution

Get both marginals first: every question here is built from them, and a single cell that fails the product rule is enough to rule out independence.

Marginals

$$p_Y(1) = 0.25 + 0.20 + 0.10 = 0.55,\qquad p_Y(0) = 0.45$$

sum along each row

$$p_X(0), p_X(1), p_X(2) = 0.55,\ 0.32,\ 0.13$$

sum down each column

Conditional pmf

$$p_{X\mid Y}(0\mid 1) = \tfrac{0.25}{0.55} = 0.455,\ \ p_{X\mid Y}(1\mid 1) = 0.364,\ \ p_{X\mid Y}(2\mid 1) = 0.182$$

divide the Y = 1 row by its own total

Independence

$$p_{XY}(0,1) = 0.25\ne p_X(0)\,p_Y(1) = 0.55\times 0.55 = 0.3025$$

one cell where the joint is not the product of the marginals is enough

Covariance

$$E[X] = 0.32 + 2(0.13) = 0.58,\qquad E[Y] = 0.55$$

means from the marginals

$$E[XY] = 1(0.20) + 2(0.10) = 0.40$$

only cells with x at least 1 and y = 1 have a non-zero product

$$\operatorname{Cov}(X,Y) = 0.40 - 0.58\times 0.55 = 0.081$$

shortcut from the box

Answer $$\boxed{p_{X\mid Y}(\cdot\mid 1) = (0.455,\ 0.364,\ 0.182),\quad \text{dependent},\quad \operatorname{Cov}(X,Y) = 0.081}$$
Check

The conditional means tell the same story as the positive covariance: $E[X\mid Y = 1] = (0.20 + 0.20)/0.55 = 0.73$ items, against $E[X\mid Y = 0] = (0.12 + 0.06)/0.45 = 0.40$.

Four row and column sums before any answer appears; every later question about the same table reuses them.

A positive covariance says that more items go together with seeing a recommendation; it does not say the recommendation caused the purchases.

Mean vector and covariance matrix of a two-feature input

A feature vector $X = [X_1, X_2]^T$ takes the four values $(0,0)$, $(1,1)$, $(2,1)$ and $(3,2)$ with chance 1/4 each. Find $\mu$ and $\Sigma$, and use $\Sigma$ to find $\operatorname{Var}(X_1 - 2X_2)$.

Find$\mu$, $\Sigma$ and $\operatorname{Var}(X_1 - 2X_2)$.
Givenfour equally likely points $(0,0), \allowbreak (1,1), \allowbreak (2,1), \allowbreak (3,2)$
Solution

Use the shortcut $E[X_iX_j] - \mu_i\mu_j$ for every entry: with four equally likely points each expectation is an average of four numbers.

Mean vector

$$\mu = \Big[\tfrac{0+1+2+3}{4},\ \tfrac{0+1+1+2}{4}\Big]^T = [1.5,\ 1]^T$$

average each coordinate over the four points

Covariance entries

$$\Sigma_{11} = \tfrac{0+1+4+9}{4} - 1.5^2 = 1.25$$

variance of the first feature

$$\Sigma_{22} = \tfrac{0+1+1+4}{4} - 1^2 = 0.5$$

variance of the second feature

$$\Sigma_{12} = \tfrac{0+1+2+6}{4} - 1.5\times 1 = 0.75$$

the products of the two coordinates are 0, 1, 2 and 6

A combination of features

$$a = [1,\,-2]^T:\quad a^T\Sigma a = 1.25 - 4(0.75) + 4(0.5) = 0.25$$

$\operatorname{Var}(a^TX) = a^T\Sigma a$, which expands to $a_1^2\Sigma_{11} + 2a_1a_2\Sigma_{12} + a_2^2\Sigma_{22}$

Answer $$\boxed{\mu = \begin{bmatrix}1.5\\ 1\end{bmatrix},\quad \Sigma = \begin{bmatrix}1.25 & 0.75\\ 0.75 & 0.5\end{bmatrix},\quad \operatorname{Var}(X_1 - 2X_2) = 0.25}$$
Check

Directly: $X_1 - 2X_2$ takes the values $0, -1, 0, -1$, with mean $-0.5$ and variance $0.25$. Also $\det\Sigma = 0.625 - 0.5625 = 0.0625\ge 0$, as positive semidefinite requires.

The covariance matrix answers the variance of every weighted sum of features at once, through $\operatorname{Var}(a^TX) = a^T\Sigma a$.

Density of a correlated Gaussian pair at two points

$X\sim N(\mu,\Sigma)$ in two dimensions, with $\mu = [0,0]^T$ and $\Sigma = \begin{bmatrix}2 & 1\\ 1 & 2\end{bmatrix}$. Evaluate the density at $P = (1,1)$ and at $Q = (1,-1)$.

Find$f_X(1,1)$ and $f_X(1,-1)$.
Given
  • $\mu = [0, 0]^T$

  • $\Sigma_{11} = \Sigma_{22} = 2$, $\Sigma_{12} = 1$

Solution

Invert the 2 by 2 matrix once with the determinant formula; after that, each point costs one quadratic form.

Determinant and inverse

$$\vert\Sigma\vert = 2\cdot 2 - 1\cdot 1 = 3,\qquad \Sigma^{-1} = \tfrac13\begin{bmatrix}2 & -1\\ -1 & 2\end{bmatrix}$$

swap the diagonal, negate the off-diagonal, divide by the determinant

Quadratic forms

$$x^T\Sigma^{-1}x = \tfrac13\big(2x_1^2 - 2x_1x_2 + 2x_2^2\big)$$

expand the product with the inverse

$$P:\ \tfrac13(2 - 2 + 2) = \tfrac23,\qquad Q:\ \tfrac13(2 + 2 + 2) = 2$$

the cross term has opposite signs at the two points

Densities

$$f_X(P) = \frac{e^{-1/3}}{2\pi\sqrt3} = \textcolor{#d1690a}{0.0658}$$

with $n = 2$ the constant is $1/(2\pi\vert\Sigma\vert^{1/2}) = 1/(2\pi\sqrt3)$

$$f_X(Q) = \frac{e^{-1}}{2\pi\sqrt3} = \textcolor{#d1690a}{0.0338}$$

same constant, larger quadratic form

Answer $$\boxed{f_X(1,1)\approx 0.0658,\qquad f_X(1,-1)\approx 0.0338}$$
Check

Both points are at distance $\sqrt2$ from the mean, yet the ratio of densities is $e^{-1/3}/e^{-1} = e^{2/3}\approx 1.95$: positive covariance favours points whose coordinates agree in sign, as the tilted contours show.

One 2 by 2 inverse and two quadratic forms. The inverse is the step to double-check: a sign slip there swaps which point looks more likely.

In a Gaussian vector the covariance decides the shape: equal distances from the mean do not mean equal densities.

Bayes' rule with a density: which class produced a reading of 1.5

A part is faulty with probability 0.2 and healthy with probability 0.8. Its sensor reading $X$ is $N(2,1)$ for a faulty part and $N(0,1)$ for a healthy one. A part reads $x = 1.5$. How likely is it to be faulty?

Find$P(Y = 1\mid X = 1.5)$
Given
  • $P(Y = 1) = 0.2$ faulty, $P(Y = 0) = 0.8$ healthy

  • $X\mid Y = 1\sim N(2,1)$ and $X\mid Y = 0\sim N(0,1)$

  • observed reading $x = 1.5$

Solution

Use Bayes' rule with the two densities as likelihoods: a single reading has probability zero, but its density plays exactly the part that the chance of the evidence played for events.

Likelihoods from the two densities

$$f_{X\mid Y}(1.5\mid 1) = \tfrac{1}{\sqrt{2\pi}}e^{-(1.5-2)^2/2} = 0.3521$$

the faulty class is centred at 2, half a unit from the reading

$$f_{X\mid Y}(1.5\mid 0) = \tfrac{1}{\sqrt{2\pi}}e^{-1.5^2/2} = 0.1295$$

the healthy class is centred at 0, one and a half units away

Bayes' rule over the two classes

$$P(Y = 1\mid 1.5) = \frac{0.2\times 0.3521}{0.2\times 0.3521 + 0.8\times 0.1295} = \frac{0.0704}{0.1740} = 0.405$$

prior times likelihood, divided by the same product summed over both classes

Answer $$\boxed{P(\text{faulty}\mid x = 1.5)\approx 0.405}$$
Check

Odds route: the likelihood ratio is $e^{(1.5^2 - 0.5^2)/2} = e^{1} = 2.718$ and the prior odds are $0.2/0.8 = 0.25$, so the posterior odds are 0.680 and the probability is $0.680/1.680 = 0.405$. The constant $1/\sqrt{2\pi}$ never mattered.

With densities Bayes' rule does not change: replace each chance of the evidence by the density of the observed value under that cause.

Checkpoint
§01.6 — can this matrix be a covariance matrix

A student estimates the covariance matrix of two features and reports $\Sigma = \begin{bmatrix}4 & 3\\ 3 & 1\end{bmatrix}$. Before using it in a Gaussian model, you check whether any random vector could have this covariance matrix.

Find(a) Can this be a covariance matrix?
Given$\Sigma_{11} = 4$, $\Sigma_{22} = 1$, $\Sigma_{12} = \Sigma_{21} = 3$
Hint 1/4

A covariance matrix has two properties. Symmetry is visible at a glance, so test the other one.

Hint 2/4

Positive semidefinite: $a^T\Sigma a\ge 0$ for every $a$. For a symmetric 2 by 2 matrix with non-negative diagonal, this is the same as $\det\Sigma\ge 0$.

Hint 3/4

Here $\det\Sigma = 4\cdot 1 - 3\cdot 3 = -5$, and with $a = [1,-2]^T$, $a^T\Sigma a = 4 - 12 + 4 = -4$.

Hint 4/4

So it cannot be a covariance matrix: the combination $X_1 - 2X_2$ would have variance $-4$.

Show solution

Look for a combination with negative variance: one such combination settles the question, while checking symmetry alone cannot.

Test positive semidefiniteness

$$\det\Sigma = 4\cdot 1 - 3\cdot 3 = -5 < 0$$

a symmetric 2 by 2 matrix with a negative determinant has one negative eigenvalue

$$a = [1,-2]^T:\quad a^T\Sigma a = 4 + 2(1)(-2)(3) + 4(1) = -4$$

the variance of X1 minus 2 X2 would be negative

Answer $$\boxed{\text{no: } \operatorname{Var}(X_1 - 2X_2) = -4 < 0}$$
Check

Size check: in size, a covariance can never exceed the product of the two standard deviations, here $2\times 1 = 2$, and 3 does.

Any estimated covariance matrix has to pass the positive semidefinite test before it goes into a Gaussian density.

⚠ Reading zero covariance as independence

'uncorrelated' and 'unrelated' sound like the same word

wrong$$\operatorname{Cov}(X,Y) = 0\ \Rightarrow\ X, Y\ \text{independent}$$
right$$X, Y\ \text{independent}\ \Rightarrow\ \operatorname{Cov}(X,Y) = 0,\ \text{not the reverse}$$
⚠ Dividing by the wrong marginal

both marginals are on the page and the formula uses only one of them

wrong$$p_{X\mid Y}(x\mid 1) = \frac{p_{XY}(x,1)}{p_X(x)}$$
right$$p_{X\mid Y}(x\mid 1) = \frac{p_{XY}(x,1)}{p_Y(1)}$$
⚠ Putting the covariance matrix in the exponent instead of its inverse

in one dimension the variance sits in a denominator, and the matrix version hides that division inside an inverse

wrong$$\exp\Big(-\tfrac12(x-\mu)^T\Sigma\,(x-\mu)\Big)$$
right$$\exp\Big(-\tfrac12(x-\mu)^T\Sigma^{-1}(x-\mu)\Big)$$

1.7Averages settle down: the law of large numbers, the CLT and Hoeffding's inequality

Says how close an average of n samples lands to its mean, and how many samples a promised accuracy costs.

In learning the distribution is unknown and all we hold is an average over n samples, such as an error rate on a test set, so we need a : a bound on how far such an average can stray.

TheoremThree results about averages
Conditions
  • LLN: $X_1, X_2,\dots$ independent and identically distributed (i.i.d.) with finite mean $E[X]$

  • CLT: i.i.d. with finite mean $\mu$ and finite variance $\sigma^2$

  • Hoeffding: $Z_1,\dots,Z_n$ independent, each with $0\le Z_i\le 1$; it holds for every $n$ and every $\varepsilon > 0$

$$\boxed{\begin{aligned} &\text{LLN:} && \bar X_n = \tfrac1n\textstyle\sum_{i=1}^{n}X_i\ \longrightarrow\ E[X]\ \text{ as } n\to\infty\\ &\text{CLT:} && \dfrac{\bar X_n - \mu}{\sigma/\sqrt n}\ \xrightarrow{d}\ N(0,1)\\ &\text{Hoeffding:} && P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le 2e^{-2n\varepsilon^2}\\ &\text{sample size:} && n\ge\frac{\ln(2/\delta)}{2\varepsilon^2}\ \Rightarrow\ \text{the bound is at most } \delta\end{aligned}}$$

The average of many independent draws settles at the mean. The CLT adds scale and shape: the typical miss shrinks like $\sigma/\sqrt n$ and looks like a bell for large $n$. Hoeffding's inequality holds at every $n$: for variables in $[0,1]$, the chance that the average misses its mean by $\varepsilon$ or more is at most $2e^{-2n\varepsilon^2}$.

Looks like this, but is not

A classifier $\hat f$ trained on 1,000 images has training error 0.02. Hoeffding with $n = 1{,}000$ and $\varepsilon = 0.05$ gives $2e^{-5}\approx 0.013$, which seems to put the true error within 0.05 of 0.02 with probability 0.987.

The training indicators are not independent draws with mean $R(\hat f)$, because $\hat f$ was chosen after seeing those same images. Hoeffding needs the rule fixed before the data it is tested on are drawn, which is why error is measured on a separate test set.

$n$bound $2e^{-2n(0.05)^2}$exact, true error 0.10exact, true error 0.50

100

1.21

0.130

0.368

200

0.736

0.0244

0.179

400

0.271

0.00126

0.0510

738

0.0499

0.0000113

0.00717

1,000

0.0135

0.00000045

0.00173

The bound never looks at the true error, so it must cover the worst case, near 0.50. At a true error of 0.10 the real chance is about 200 times smaller at n = 400 and 4,000 times smaller at n = 738. A bound above 1, as at n = 100, says nothing.

Five tails in a row: what the law of large numbers does and does not say

A fair coin has shown tails 5 times in a row. Find the chance of heads on the next toss. Then, if the coin is tossed 995 more times, find the expected share of heads among all 1,000 tosses.

FindThe chance of heads next, and the expected share of heads after 1,000 tosses.
Given
  • fair coin, independent tosses

  • the first 5 tosses were tails

Solution

Separate the past, which is fixed, from the future, which is still random: independence settles the first question and linearity of expectation settles the second.

Next toss

$$P(\text{H on toss 6}\mid \text{5 tails}) = P(\text{H on toss 6}) = \tfrac12$$

independent tosses: the past changes nothing

Share after 1,000 tosses

$$E[\text{heads}] = 0 + 995\times\tfrac12 = 497.5$$

the first 5 gave no heads; each later toss contributes one half on average

$$\frac{497.5}{1{,}000} = 0.4975$$

the early tails are diluted, not paid back

Answer $$\boxed{P(\text{heads next}) = \tfrac12,\qquad \text{expected share} = 0.4975}$$
Check

Push it further: after $m$ more tosses the expected share is $\frac{m/2}{m+5}$, which tends to $\tfrac12$ as $m\to\infty$, exactly as the law of large numbers says, without any toss ever favouring heads.

Averages converge because a fixed early streak weighs less and less, not because the coin corrects itself. Believing the second is the gambler's fallacy.

How far can a click rate over 100 users drift? CLT against Hoeffding

Each of 100 users clicks independently with probability 0.2. Estimate the chance that the observed click rate lands at least 0.08 away from 0.2, first with the CLT and then with Hoeffding's bound.

Find$P(\vert\bar X - 0.2\vert\ge 0.08)$ approximately, and a guaranteed upper bound.
Given
  • $X_i\sim\mathrm{Ber}(0.2)$, i.i.d.

  • $n = 100$, $\varepsilon = 0.08$

  • for $Z\sim N(0,1)$: $P(\vert Z\vert\ge 2) = 0.0455$

Solution

Standardise with the CLT for an estimate, then use Hoeffding for a guarantee; they answer different questions, so doing both shows what each is worth.

Scale of the average

$$\mu = 0.2,\qquad \sigma = \sqrt{0.2\times 0.8} = 0.4,\qquad \frac{\sigma}{\sqrt n} = \frac{0.4}{10} = 0.04$$

Bernoulli variance p(1 − p), then the CLT scale

CLT estimate

$$P(\vert\bar X - 0.2\vert\ge 0.08)\approx P(\vert Z\vert\ge 2) = 0.0455$$

0.08 is two standard deviations of the average

Hoeffding guarantee

$$2e^{-2\times 100\times 0.08^2} = 2e^{-1.28} = 0.556$$

valid for any distribution on [0, 1], so it cannot use the small variance 0.16

Answer $$\boxed{\text{CLT}\approx 0.046,\qquad \text{Hoeffding}\le 0.556}$$
Check

Exact binomial value: for $X\sim\mathrm{Binomial}(100, 0.2)$, $P(X\le 12) + P(X\ge 28) = 0.0595$. The CLT is close but a little low at $n = 100$; Hoeffding is far above, but it is a guarantee.

The CLT approximates and Hoeffding guarantees. When an answer has to be promised at a fixed n, only the guarantee will do.

The opening question: 400 photos, 36 errors, and the size of a promise

A face recognizer $f$, fixed before testing, makes 36 errors on 400 test photos drawn independently. Bound the chance that the measured error misses the true error $R(f)$ by 0.05 or more. Then find how many test photos guarantee a miss below 0.02, except with chance at most 0.05.

FindThe Hoeffding bound at n = 400, and the smallest n for the promise.
Given
  • $n = 400$ i.i.d. test pairs, $f$ fixed in advance

  • 36 errors, so $\hat R_{400}(f) = 0.09$

  • then $\varepsilon = 0.02$ with $\delta = 0.05$

Solution

Write the error rate as an average of indicators first. That is the one step where the machine learning turns into probability, and after it Hoeffding applies directly.

Turn the error into an average

$$Z_i = I\big(f(X_i)\ne Y_i\big)\in\{0,1\},\qquad \hat R_n(f) = \bar Z$$

each test pair gives one indicator, and the measured error is their average

$$E\big[\hat R_n(f)\big] = R(f)$$

linearity, with $E[Z_i] = P(f(X_i)\ne Y_i) = R(f)$

$$Z_1,\dots,Z_n\ \text{independent}$$

the pairs are i.i.d. and f was fixed before they were drawn

Evaluate the bound at n = 400

$$P\big(\vert\hat R_{400} - R(f)\vert\ge 0.05\big)\le 2e^{-2\times 400\times 0.05^2} = 2e^{-2} = \textcolor{#6f42c1}{0.271}$$

Hoeffding with n = 400 and ε = 0.05

Solve for the sample size

$$2e^{-2n(0.02)^2}\le 0.05\iff n\ge\frac{\ln 40}{2(0.02)^2} = 4611.1$$

take logarithms; $\ln(2/0.05) = \ln 40 = 3.689$

$$n = \textcolor{#d1690a}{4{,}612}$$

round up: 4,611 photos would leave the bound just above 0.05

Answer $$\boxed{\text{bound at } n = 400:\ 0.271,\qquad \text{needed: } n = 4{,}612}$$
Check

Plug back in: $2e^{-2\times 4612\times 0.0004} = 0.04996\le 0.05$, while $n = 4{,}611$ gives $0.050004$. And if the true error really were 0.14, the exact chance of measuring 0.09 or less on 400 photos is about 0.0016, far below 0.271.

Three lines once the error is written as an average of indicators; that rewriting is the step most easily skipped.

So the honest report is: 0.09 measured on 400 photos, and Hoeffding alone cannot rule out 0.14. With 4,612 photos, the measured value is guaranteed to be within 0.02 of the truth, except with chance at most 1 in 20.

Further reading: the same promise from Chebyshev's inequality

This one is not on the lecture slides; it is here as a yardstick. Using $I(\vert\bar Z - \mu\vert\ge\varepsilon)\le(\bar Z - \mu)^2/\varepsilon^2$, bound the chance of a miss of $\varepsilon$, and compare the sample sizes for $\varepsilon = 0.05$ at $\delta = 0.05$ and at $\delta = 0.001$ with Hoeffding's.

FindChebyshev's sample sizes next to Hoeffding's.
Given
  • $Z_i$ independent in $[0,1]$, $\mu = E[\bar Z]$

  • $\varepsilon = 0.05$

  • $\delta = 0.05$ and $\delta = 0.001$

Solution

Take expectations of the indicator inequality: it uses only the variance, which is exactly why it will lose to Hoeffding.

Chebyshev from the indicator trick

$$P(\vert\bar Z - \mu\vert\ge\varepsilon) = E\big[I(\vert\bar Z - \mu\vert\ge\varepsilon)\big]\le\frac{\operatorname{Var}(\bar Z)}{\varepsilon^2}$$

where the indicator is 1 the right side is at least 1, and where it is 0 the right side is still non-negative

Variance of the average

$$\operatorname{Var}(\bar Z) = \frac{1}{n^2}\sum_{i=1}^{n}\operatorname{Var}(Z_i)\le\frac{1}{4n}$$

independent terms add their variances, and on $[0,1]$, $Z^2\le Z$ gives $\operatorname{Var}(Z_i)\le\mu_i(1-\mu_i)\le\tfrac14$

Compare the sample sizes

$$\frac{1}{4n\varepsilon^2}\le\delta\iff n\ge\frac{1}{4\varepsilon^2\delta}$$

force the Chebyshev bound under δ

$$\delta = 0.05:\ 2{,}000\text{ vs } 738;\qquad \delta = 0.001:\ 100{,}000\text{ vs } 1{,}521$$

Hoeffding's size grows only with the logarithm of 1/δ

Answer $$\boxed{\text{Chebyshev: } n\ge\frac{1}{4\varepsilon^2\delta}\qquad \text{Hoeffding: } n\ge\frac{\ln(2/\delta)}{2\varepsilon^2}}$$
Check

At $\delta = 0.001$: $1/(4\times 0.0025\times 0.001) = 100{,}000$, while $\ln(2{,}000)/0.005 = 1520.2$ rounds up to 1,521. Making the failure chance 50 times smaller costs Chebyshev 50 times more data and Hoeffding about twice as much.

Exponential tails make very small failure chances cheap, which is why Hoeffding, not Chebyshev, is the tool for test sets.

Checkpoint
§01.7 — evaluating Hoeffding's bound

A spam filter, fixed in advance, is run on 200 test emails drawn independently. Its measured error rate $\hat R_{200}$ is the average of 200 indicators, one per email.

Find(a) What upper bound does Hoeffding's inequality give for $P(\vert\hat R_{200} - R\vert\ge 0.1)$?
Given
  • $n = 200$

  • $\varepsilon = 0.1$

  • each indicator is 0 or 1

Hint 1/4

Check the conditions first: independent terms, each between 0 and 1. Then it is a matter of plugging in.

Hint 2/4

$P(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon)\le 2e^{-2n\varepsilon^2}$.

Hint 3/4

With $n = 200$ and $\varepsilon = 0.1$: $2n\varepsilon^2 = 2\times 200\times 0.01 = 4$, so the bound is $2e^{-4}$.

Hint 4/4

So the bound is $2e^{-4}\approx 0.037$.

Show solution

Compute the exponent on its own line first; the usual slips, a missing square or a missing 2, happen when everything is typed at once.

Exponent

$$2n\varepsilon^2 = 2\times 200\times (0.1)^2 = 4$$

square the tolerance before multiplying

Bound

$$2e^{-4} = 2\times 0.0183 = 0.0366$$

the factor 2 covers misses on both sides

Answer $$\boxed{P(\vert\hat R_{200} - R\vert\ge 0.1)\le 0.037}$$
Check

Scale check: at $n = 200$ a miss of 0.1 is about three standard deviations of an error rate near 0.5, since $\sqrt{0.25/200} = 0.035$, so a small bound like 0.037 is plausible.

Always compute 2nε² on its own line; it is the number that decides everything else.

⚠ Dropping the factor 2 in front

the one-sided version has no 2, and it is easy to remember the wrong one

wrong$$P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le e^{-2n\varepsilon^2}$$
right$$P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le 2e^{-2n\varepsilon^2}$$
⚠ Using Hoeffding on data outside [0, 1] without rescaling

the inequality is quoted for [0, 1] and the range condition is easy to skip

wrong$$X_i\in[2,6]:\ P(\vert\bar X - \mu\vert\ge 0.1)\le 2e^{-2n(0.1)^2}$$
right$$Z_i = \tfrac{X_i - 2}{4}:\ P(\vert\bar X - \mu\vert\ge 0.1)\le 2e^{-2n(0.1/4)^2}$$
⚠ Rounding the sample size down

truncating a decimal is a habit, and 737.8 looks close enough to 737

wrong$$n\ge 737.8\ \Rightarrow\ n = 737$$
right$$n\ge 737.8\ \Rightarrow\ n = 738$$
Bayes' rule by counting a population

Any 'given a positive signal, how likely is the cause' question, especially when the cause is rare.

  1. Pick a population

    Choose a round number, such as 100,000, large enough that the rarest branch gets a whole count.

  2. Split by the prior

    Multiply by $P(A)$ and by $P(A^c)$ to get the two groups.

  3. Split by the likelihoods

    In each group, multiply by the chance of the evidence in that group.

  4. Keep the evidence

    Add the counts that show the evidence. This sum is the denominator.

  5. Divide

    The posterior is the evidence count inside $A$ over the total evidence count.

Where it goes wrong
  • Stopping at the numerator, which gives the joint chance instead of the conditional one.

  • Applying the hit rate to the whole population instead of only to the group that has the cause.

  • Picking a population so small that the rare branch holds a fraction of a person, which hides the denominator again.

Expectation by indicators

The mean of a count whose pmf is awkward, unknown or not needed.

  1. Name the events

    Write the count as the number of events $A_1,\dots,A_m$ that happen, one event per item.

  2. Write the sum

    $N = \sum_{i=1}^{m}I(A_i)$.

  3. One probability per term

    $E[I(A_i)] = P(A_i)$.

  4. Add

    $E[N] = \sum_i P(A_i)$, with no independence needed.

Where it goes wrong
  • Using the same shortcut for the variance, which does need the covariances between the indicators.

  • Defining the events so that one item can be counted twice.

Test-set size from Hoeffding's inequality

Any promise of the form 'the measured average is within $\varepsilon$ of the truth, except with chance at most $\delta$'.

  1. Check the conditions

    Independent terms, each in a known range, and the rule being tested fixed before the data are drawn.

  2. Rescale to [0, 1]

    $Z = (X - a)/(b - a)$, and divide the tolerance by $b - a$ as well.

  3. Put the bound under δ

    $2e^{-2n\varepsilon^2}\le\delta$.

  4. Solve and round up

    $n\ge\ln(2/\delta)/(2\varepsilon^2)$, then the next whole number.

  5. Say it in words

    Within the tolerance of the truth, except with chance at most $\delta$.

Where it goes wrong
  • Leaving the tolerance on the original scale after rescaling the data.

  • Using the training set, whose indicators depend on the fitted rule.

  • Dropping the 2 in front of the exponential, which undersizes n and quietly doubles the real failure chance.

Disjoint: an image labelled cat and labelled dog

One image is a cat with probability 0.5 and a dog with probability 0.5, never both. Are the events 'cat' and 'dog' independent?

FindWhether the product rule holds.
Given
  • $P(\text{cat}) = P(\text{dog}) = 0.5$

  • an image cannot be both

Solution

Test the product rule directly; the feeling that the two events are unrelated is exactly what the numbers contradict.

Product rule

$$P(\text{cat}\cap\text{dog}) = 0$$

one image cannot be both

$$P(\text{cat})\,P(\text{dog}) = 0.25\ne 0$$

product of the two separate chances

Answer $$\boxed{\text{disjoint, so dependent}}$$
Check

Conditional check: $P(\text{dog}\mid\text{cat}) = 0$, far from $P(\text{dog}) = 0.5$.

Independent: a click and the device used

From 1,000 sessions, $P(\text{mobile}) = 0.6$, $P(\text{click}) = 0.15$ and $P(\text{click}\cap\text{mobile}) = 0.09$. Are the two events independent? Are they disjoint?

FindIndependence and disjointness.
Given
  • $P(\text{mobile}) = 0.6$

  • $P(\text{click}) = 0.15$

  • $P(\text{click}\cap\text{mobile}) = 0.09$

Solution

Run both tests on the same three numbers, so the difference between the two ideas is visible side by side.

Product rule

$$0.6\times 0.15 = 0.09 = P(\text{click}\cap\text{mobile})$$

the joint chance equals the product

Disjoint?

$$P(\text{click}\cap\text{mobile}) = 0.09 > 0$$

90 of the 1,000 sessions are both

Answer $$\boxed{\text{independent, not disjoint}}$$
Check

Conditional check: $P(\text{click}\mid\text{mobile}) = 0.09/0.6 = 0.15 = P(\text{click})$.

Disjoint events exclude each other, so each one tells you everything about the other; independent events leave each other's chances untouched.

How to tell them apart

Compute $P(A\cap B)$ and $P(A)P(B)$. Disjoint makes the first zero; independent makes the two equal. Both at once is possible only when one event has probability zero.

Reading P(flag given fraud) off the specification

The fraud detector from this section flags 99 of every 100 fraudulent transactions and 2 of every 100 legitimate ones, and 1 transaction in 1,000 is fraud. What share of frauds get flagged?

Find$P(\text{flag}\mid\text{fraud})$
Given
  • $P(\text{flag}\mid\text{fraud}) = 0.99$

  • $P(\text{fraud}) = 0.001$

Solution

Identify which event is known to have happened before computing anything; here it is the fraud.

The known event goes after the bar

$$\text{known: fraud}\ \Rightarrow\ P(\text{flag}\mid\text{fraud})$$

the question stays inside the fraud branch

$$= 0.99$$

this is the hit rate stated in the specification

Answer $$\boxed{P(\text{flag}\mid\text{fraud}) = 0.99}$$
Check

No base rate was needed, since the question never leaves the fraud branch: 99 of the 100 frauds are flagged.

Computing P(fraud given flag) needs the base rate

Same detector and the same rates. A transaction has been flagged. How likely is it to be fraud?

Find$P(\text{fraud}\mid\text{flag})$
Given
  • $P(\text{flag}\mid\text{fraud}) = 0.99$

  • $P(\text{flag}\mid\text{legit}) = 0.02$

  • $P(\text{fraud}) = 0.001$

Solution

Now the flag is the known event, so both branches that can produce a flag enter the denominator.

The known event goes after the bar

$$\text{known: flag}\ \Rightarrow\ P(\text{fraud}\mid\text{flag})$$

the question spans both branches

Bayes' rule

$$\frac{0.99\times 0.001}{0.99\times 0.001 + 0.02\times 0.999} = \frac{0.00099}{0.02097} = 0.047$$

prior times likelihood over the total chance of a flag

Answer $$\boxed{P(\text{fraud}\mid\text{flag})\approx 0.047}$$
Check

Counts: 99 of the 2,097 flagged transactions in every 100,000 are fraud.

The two conditionals use the same two events and here differ by a factor of about 21, because only the second one has to account for how rare fraud is.

How to tell them apart

Put the event you know has happened after the bar. If that event is the cause, read the rate off the model; if it is the evidence, you need Bayes' rule and a prior.

Scaffolding comes off
The common skeleton
  1. Name the variables being averaged, and check that they are independent, lie in a known range $[a,b]$, and come from a rule fixed before the data were drawn.

  2. Rescale to $[0,1]$ with $Z = (X-a)/(b-a)$; a tolerance $t$ on the original scale becomes $\varepsilon = t/(b-a)$.

  3. Write Hoeffding for the rescaled average: $P(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon)\le 2e^{-2n\varepsilon^2}$.

  4. Force the bound under the allowed failure chance: $2e^{-2n\varepsilon^2}\le\delta$.

  5. Solve $n\ge\ln(2/\delta)/(2\varepsilon^2)$ and round up.

  6. State the promise on the original scale, in one sentence.

1 · fully worked

Star ratings from 1 to 5: how many to pin the mean within 0.2 stars

A product page shows the average star rating of randomly chosen buyers. Each rating is a whole number from 1 to 5, and ratings are independent. The shop wants the displayed average within 0.2 stars of the true mean rating, except with chance at most 0.05. How many ratings are needed?

FindThe smallest number of ratings.
Given
  • ratings $X_i\in[1,5]$, independent

  • tolerance 0.2 stars

  • $\delta = 0.05$

Solution

Rescale first, because Hoeffding is stated for [0, 1]; rescaling after solving would leave the tolerance on the wrong scale.

Rescale to [0, 1]

$$Z_i = \frac{X_i - 1}{4}\in[0,1],\qquad \bar Z = \frac{\bar X - 1}{4}$$

subtract the lowest rating and divide by the range, 5 − 1 = 4

$$\vert\bar X - \mu\vert\ge 0.2\iff\vert\bar Z - E[\bar Z]\vert\ge\tfrac{0.2}{4} = 0.05$$

the same division shrinks the tolerance, so ε = 0.05

Bound and solve

$$2e^{-2n(0.05)^2}\le 0.05$$

Hoeffding for the rescaled average, forced under δ

$$n\ge\frac{\ln(2/0.05)}{2(0.05)^2} = \frac{3.689}{0.005} = 737.8$$

take natural logarithms of both sides

$$n = 738$$

round up to the next whole rating

Say it on the star scale

$$P\big(\vert\bar X - \mu\vert\ge 0.2\big)\le 0.05\ \text{ for } n = 738$$

the promise is about stars, so it is stated in stars

Answer $$\boxed{n = 738\ \text{ratings}}$$
Check

Plug back in: $2e^{-2\times 738\times 0.0025} = 0.0499\le 0.05$, while $n = 737$ gives $0.0502$. It matches the crossing in the Hoeffding figure, as it should: after rescaling this is the same problem.

The range of the data enters only through the rescaled tolerance: halve the range and the same promise needs a quarter of the samples.

2 · you write the reasoning

Easier than the rung above: the data are already in [0, 1], so nothing is rescaled. Each visitor clicks (1) or not (0), independently. How many visitors make the measured click rate land within 0.1 of the true rate, except with chance at most 0.02? The steps are done; write why each line is allowed.

  1. $$Z_i = I(\text{visitor } i \text{ clicks})\in\{0,1\}\subseteq[0,1]$$

    reasoning

    Each click indicator is 0 or 1, so it already lies in [0, 1], and visitors act independently: both conditions of Hoeffding hold without rescaling.

  2. $$\varepsilon = 0.1,\qquad \delta = 0.02$$

    reasoning

    The tolerance is on the rate itself, which already lives on the [0, 1] scale, so it goes in unchanged; δ is the failure chance the promise may allow.

  3. $$2e^{-2n(0.1)^2}\le 0.02$$

    reasoning

    Hoeffding's bound for the click rate, forced under δ: if the bound on the failure chance is at most 0.02, the failure chance itself is too.

  4. $$n\ge\frac{\ln(2/0.02)}{2(0.1)^2} = \frac{\ln 100}{0.02} = 230.3$$

    reasoning

    Divide by 2, take natural logarithms and divide by $2\varepsilon^2$: the inequality is the same as $2n\varepsilon^2\ge\ln(2/\delta)$, and $\ln 100 = 4.605$.

  5. $$n = 231$$

    reasoning

    Round up: n = 230 leaves the bound at 0.0201, just above 0.02, while n = 231 brings it to 0.0197.

3 · find the buried error

Harder than the rung above: the data need rescaling, and the work below was done badly.

  • A voltage sensor gives independent readings between 2 V and 6 V.
  • Goal: an average within 0.1 V of the true mean, except with chance at most 0.01.
  • Exactly two of the four steps contain a mistake. A later step may carry a wrong number forward without making a new one.
  1. Step 1. The readings are independent and lie in $[2,6]$, so $Z_i = (X_i - 2)/4\in[0,1]$.

  2. Step 2. Rescaling does not change the gap we want, so the tolerance stays $\varepsilon = 0.1$.

  3. Step 3. Require the bound to be at most the failure chance: $e^{-2n\varepsilon^2}\le 0.01$.

  4. Step 4. Solving, $n\ge\ln(100)/(2\times 0.1^2) = 230.3$, so $n = 231$ readings.

the two buried errors (2)
⚠ step 2

The tolerance was left on the volt scale. After the readings are divided by the range 4, a gap of 0.1 V becomes a gap of 0.1/4 = 0.025 on the [0, 1] scale.

The data get rescaled because the theorem demands it, and the tolerance, which the theorem never names, is forgotten.

right

$\varepsilon = 0.1/4 = 0.025$.

⚠ step 3

The factor 2 in front of the exponential is missing, which gives the bound for a miss on one side only.

The one-sided and two-sided versions differ only by that 2, and 'within 0.1 V' is a two-sided promise.

right

$2e^{-2n\varepsilon^2}\le 0.01$, so $n\ge\ln(200)/(2\times 0.025^2) = 4238.7$ and $n = 4{,}239$.

4 · the bare problem
§01.7 — sample size for a 0 to 10 score

A survey asks randomly chosen users for a satisfaction score between 0 and 10, and the answers are independent. The team wants the average score within 0.25 of the true mean score, except with chance at most 0.02.

Find(a) How many users must be surveyed?
Given
  • scores in $[0,10]$, independent

  • tolerance 0.25 on the score scale

  • $\delta = 0.02$

Hint 1/4

The inequality you need is stated for [0, 1], and the scores are not in [0, 1]. Decide what has to change before any formula.

Hint 2/4

Rescale $Z = X/10$, so the tolerance becomes $\varepsilon = 0.25/10$; then $n\ge\ln(2/\delta)/(2\varepsilon^2)$.

Hint 3/4

With $\varepsilon = 0.025$ and $\delta = 0.02$: $n\ge\ln(100)/(2\times 0.025^2) = 4.605/0.00125$.

Hint 4/4

So $n\ge 3684.1$, and 3,685 users are needed.

Show solution

Rescale by the range first, as in the ladder; the rest is the same five lines.

Rescale

$$Z_i = \frac{X_i}{10}\in[0,1],\qquad \varepsilon = \frac{0.25}{10} = 0.025$$

the lowest score is 0, so only the division by the range is needed

Solve

$$n\ge\frac{\ln(2/0.02)}{2(0.025)^2} = \frac{4.605}{0.00125} = 3684.1$$

Hoeffding forced under δ, then logarithms

$$n = 3{,}685$$

round up

Answer $$\boxed{n = 3{,}685}$$
Check

Plug back in: $2e^{-2\times 3685\times 0.000625} = 0.01998\le 0.02$, while 3,684 users give $0.020003$, just above.

Rescale the tolerance together with the data; everything after that is identical from problem to problem.

Full exam-style question

A held-out error estimate, from indicators to a sample sizeexam format

A classifier f is trained on one dataset and then frozen. It is evaluated on a separate test set of n pairs drawn independently from the same source, with true error $R(f) = P(f(X)\ne Y)$ and measured error $\hat R_n(f) = \frac1n\sum_i I(f(X_i)\ne Y_i)$.

  • (a) Show that $E[\hat R_n(f)] = R(f)$.
  • (b) With $n = 2{,}000$ test pairs and 170 errors, bound the chance that $\hat R_n$ misses $R(f)$ by 0.03 or more.
  • (c) How large must $n$ be to guarantee a miss below 0.02, except with chance at most 0.01?
  • (d) Would the bound in (b) hold if the 2,000 pairs had been the training set?
FindUnbiasedness, one bound, one sample size, and a yes or no with a reason.
Given
  • $f$ frozen before the test set is drawn

  • $n = 2{,}000$, 170 errors

  • tolerances 0.03 in (b); 0.02 with $\delta = 0.01$ in (c)

Solution

Do (a) with indicators and linearity, because (b) and (c) both lean on it: Hoeffding bounds the gap to the mean, so the mean has to be R(f).

(a) Unbiasedness from linearity

$$E\big[\hat R_n(f)\big] = \frac1n\sum_{i=1}^{n}E\big[I(f(X_i)\ne Y_i)\big]$$

linearity of expectation

$$= \frac1n\sum_{i=1}^{n}P\big(f(X_i)\ne Y_i\big) = \frac1n\cdot nR(f) = R(f)$$

indicator rule, and each test pair has the distribution of (X, Y)

(b) Bound at n = 2,000

$$\hat R_{2000}(f) = \tfrac{170}{2000} = 0.085$$

the measured value, for the record

$$P\big(\vert\hat R_n - R(f)\vert\ge 0.03\big)\le 2e^{-2\times 2000\times 0.03^2} = 2e^{-3.6} = 0.0546$$

indicators in {0, 1}, independent because f was frozen before the pairs were drawn

(c) Sample size

$$n\ge\frac{\ln(2/0.01)}{2(0.02)^2} = \frac{5.298}{0.0008} = 6622.9$$

solve $2e^{-2n\varepsilon^2}\le\delta$

$$n = 6{,}623$$

round up

(d) The training set

$$\hat f\ \text{depends on the pairs}\ \Rightarrow\ \text{the indicators are not independent draws centred at } R(\hat f)$$

the rule was chosen to do well on these very pairs, so part (a) and Hoeffding both fail

Answer $$\boxed{\text{(a) } E[\hat R_n] = R(f)\quad \text{(b) } \le 0.055\quad \text{(c) } n = 6{,}623\quad \text{(d) no}}$$
Check

For (c), plug back in: $2e^{-2\times 6623\times 0.0004} = 0.009999\le 0.01$, while $n = 6{,}622$ gives $0.010007$. For (b), in words: over repeated test sets of 2,000, the measured error lands within 0.03 of $R(f)$ at least 945 times in 1,000.

Parts (b) and (c) need a calculator; parts (a) and (d) need only the definitions.

The whole chapter meets in this one question: indicators turn an error into an average, linearity centres it, independence licenses Hoeffding, and a logarithm turns the bound into a sample size.

Practice

A · concept 4 questions
1§01.1 — does zero training error mean zero test error

A classifier is trained on 2,000 labelled images and makes no mistakes on them. The team concludes that it will make no mistakes on new images from the same camera.

Find(a) True or false: zero training error implies zero error on new images from the same source.
Given
  • 0 mistakes on the 2,000 training images

  • new images come from the same source

Hint 1/4

Look for a single rule that has zero training error and is still bad on new images; one such rule settles the claim.

Hint 2/4

A rule is judged by its error on pairs it has not seen: $P(\hat f(X)\ne Y)$ for a new pair $(X, Y)$.

Hint 3/4

The memorising filter from this section made 0 mistakes on its 1,000 training emails and 30 mistakes in every 100 new ones.

Hint 4/4

So the claim is false: zero training error does not imply zero error on new data.

Show solution

A claim about every classifier falls to one counterexample, and the memoriser is the simplest one.

Build the counterexample

$$\hat f(x) = \begin{cases} y_i & x = x_i\\ \text{not spam} & \text{otherwise}\end{cases}$$

store every training pair and answer a default anywhere else

$$\text{training error} = 0$$

each stored input gets its own label back

Error on new data

$$P(\hat f(X)\ne Y) = P(Y = \text{spam}) = 0.30$$

new inputs are never stored, so the default is wrong exactly on spam

Answer $$\boxed{\text{false}}$$
Check

Independent of the example: whenever the labels carry noise, even the true rule misclassifies some new pairs, so zero error on new data is out of reach for any rule.

Training error measures fit to the examples seen; only data held out from training measure performance.

2§01.3 — are exclusive events independent

In a dataset every image has exactly one label. 'The label is cat' has probability 0.4 and 'the label is dog' has probability 0.3. A classmate says that since the two labels never occur together, the events are independent.

Find(a) True or false: 'cat' and 'dog' are dependent events.
Given
  • $P(\text{cat}) = 0.4$

  • $P(\text{dog}) = 0.3$

  • no image has both labels

Hint 1/4

Independence is a numerical condition, not a story; compute both of its sides.

Hint 2/4

$A, B$ independent $\iff P(A\cap B) = P(A)\,P(B)$.

Hint 3/4

Here $P(\text{cat}\cap\text{dog}) = 0$, while $P(\text{cat})\,P(\text{dog}) = 0.4\times 0.3 = 0.12$.

Hint 4/4

So the product rule fails, the events are dependent, and the statement is true.

Show solution

Compute both sides of the product rule; the question is settled by two numbers.

Two sides of the product rule

$$P(\text{cat}\cap\text{dog}) = 0$$

no image carries both labels

$$P(\text{cat})\,P(\text{dog}) = 0.4\times 0.3 = 0.12$$

product of the separate chances

Compare

$$0\ne 0.12$$

the product rule fails, so the events are dependent

Answer $$\boxed{\text{true: dependent}}$$
Check

Conditional check: $P(\text{dog}\mid\text{cat}) = 0$, while $P(\text{dog}) = 0.3$; learning one label changed the other's chance.

Exclusive events with positive chances are always dependent; independence needs overlap in exactly the right proportion.

3§01.4 — a density value above 1

A continuous random variable $X$, a response time in seconds, has a pdf with $f_X(2) = 3$. A teammate says the pdf must be wrong, since a probability cannot be 3.

Find(a) Which conclusion is correct?
Given
  • $X$ is continuous

  • $f_X(2) = 3$

Hint 1/4

Ask what a pdf value measures: a probability, or probability per unit length?

Hint 2/4

For continuous $X$: $P(a\le X\le b) = \int_a^b f_X(x)\,dx$ and $P(X = x) = 0$; the only size condition is a total area of 1.

Hint 3/4

With $f_X(2) = 3$, a narrow interval gives $P(2\le X\le 2.01)\approx 3\times 0.01 = 0.03$, a perfectly good probability.

Hint 4/4

So nothing is wrong: a density value may be larger than 1.

Show solution

Translate the height into a probability over a small interval; that is the only way a pdf value turns into a probability.

Height times width

$$P(2\le X\le 2 + h)\approx f_X(2)\,h = 3h$$

for a small width h the area is about height times width

A concrete width

$$h = 0.01:\ 3\times 0.01 = 0.03$$

a valid probability

$$P(X = 2) = 0$$

a single point carries no probability for a continuous variable

Answer $$\boxed{\text{nothing is wrong}}$$
Check

A valid density that reaches 3: the uniform density on [0, 1/3] has height 3 everywhere on its range, and area 3 × 1/3 = 1.

Only areas under a pdf are probabilities; heights just have to be non-negative.

4§01.7 — does Hoeffding need identical distributions

Five hundred independent test images come from five different cameras, so the chance of an error differs from image to image. A teammate says Hoeffding's inequality cannot be used, because the error indicators are not identically distributed.

Find(a) True or false: Hoeffding's inequality still applies to these indicators, even though their error chances differ.
Given
  • indicators $Z_i\in\{0,1\}$, independent

  • different error chances for different cameras

Hint 1/4

List exactly what the theorem assumes before deciding whether this situation meets it.

Hint 2/4

Hoeffding: $Z_1,\dots,Z_n$ independent with $0\le Z_i\le 1$ gives $P(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon)\le 2e^{-2n\varepsilon^2}$.

Hint 3/4

Here the indicators are independent and each lies in $\{0,1\}$; $E[\bar Z]$ is the average of the 500 images' error chances.

Hint 4/4

So the statement is true: the bound applies, centred at the average error chance.

Show solution

Match the situation against the theorem's conditions literally, instead of against the usual example of i.i.d. data.

Conditions

$$Z_i\in\{0,1\}\subseteq[0,1],\qquad Z_i\ \text{independent}$$

both conditions of the theorem hold

Centre of the bound

$$E[\bar Z] = \frac1n\sum_{i=1}^{n}P(Z_i = 1)$$

the centre is the average of the individual error chances

Answer $$\boxed{\text{true: independence and range suffice}}$$
Check

For $n = 500$ and $\varepsilon = 0.05$, the bound $2e^{-2.5} = 0.164$ holds here exactly as it would with a single camera.

Read a theorem's conditions literally: Hoeffding asks for independence and a bounded range, nothing about identical distributions.

B · computation 9 questions
1§01.2 — three stages, three ways to bound a failure

A nightly data-processing job has three stages that fail independently, with probabilities 0.05, 0.02 and 0.01. The job fails if at least one stage fails.

Find
  1. (a) Give the union bound on the chance that the job fails.

  2. (b) Find the exact chance, using independence.

  3. (c) Give the lower bound that the order property provides.

Given
  • $P(A_1) = 0.05$, $P(A_2) = 0.02$, $P(A_3) = 0.01$

  • stages fail independently

  • failure means at least one stage fails

Hint 1/4

'At least one fails' is a union; its complement, 'none fails', is an intersection, which independence makes easy.

Hint 2/4

Union bound: $P(\cup A_i)\le\sum P(A_i)$. Exact: $P(\cup A_i) = 1 - \prod(1 - P(A_i))$ for independent events. Order: $P(\cup A_i)\ge\max_i P(A_i)$.

Hint 3/4

With 0.05, 0.02 and 0.01: the sum is 0.08, the complements multiply to $0.95\times 0.98\times 0.99 = 0.92169$, and the largest single chance is 0.05.

Hint 4/4

So (a) at most 0.08, (b) 0.0783 and (c) at least 0.05.

Show solution

Go through the complement for the exact value: 'none fails' is a product of three numbers, while the union directly would need inclusion and exclusion.

(a) Union bound

$$P(A_1\cup A_2\cup A_3)\le 0.05 + 0.02 + 0.01 = 0.08$$

valid whatever the dependence

(b) Exact, under independence

$$P(\text{no failure}) = 0.95\times 0.98\times 0.99 = 0.92169$$

complements of independent events are independent, so their chances multiply

$$P(\text{failure}) = 1 - 0.92169 = 0.0783$$

complement rule

(c) Order property

$$A_1\subseteq\textstyle\bigcup_i A_i\ \Rightarrow\ P(\text{failure})\ge 0.05$$

the union contains the likeliest single failure

Answer $$\boxed{0.05\le P(\text{failure}) = 0.0783\le 0.08}$$
Check

Inclusion and exclusion gives the same exact value: $0.08 - (0.001 + 0.0005 + 0.0002) + 0.00001 = 0.07831$.

The union bound overshoots by roughly the pairwise overlaps, which are tiny for rare failures; that is why it is so often good enough.

2§01.3 — a spam filter read in both directions

In a company inbox, 40 of every 100 emails are spam. The filter flags 95 of every 100 spam emails and 3 of every 100 normal emails.

Find
  1. (a) Find $P(S\mid F)$, the chance that a flagged email is spam.

  2. (b) Find $P(S\mid F^c)$, the chance that an unflagged email is spam.

Given
  • $P(S) = 0.40$

  • $P(F\mid S) = 0.95$

  • $P(F\mid S^c) = 0.03$

Hint 1/4

Two different conditioning events: a flag in (a), no flag in (b). Each needs its own denominator.

Hint 2/4

$P(S\mid F) = \dfrac{P(F\mid S)P(S)}{P(F)}$ and $P(S\mid F^c) = \dfrac{P(F^c\mid S)P(S)}{1 - P(F)}$, with $P(F) = P(F\mid S)P(S) + P(F\mid S^c)P(S^c)$.

Hint 3/4

$P(F) = 0.95\times 0.40 + 0.03\times 0.60 = 0.38 + 0.018 = 0.398$, and $P(F^c\mid S) = 0.05$.

Hint 4/4

So (a) $0.38/0.398 = 0.955$ and (b) $0.02/0.602 = 0.033$.

Show solution

Compute the total chance of a flag once; both answers use it, one directly and one through its complement.

Total chance of a flag

$$P(F) = 0.95(0.40) + 0.03(0.60) = 0.398$$

law of total probability over spam and normal

(a) Flagged

$$P(S\mid F) = \frac{0.38}{0.398} = 0.955$$

Bayes' rule

(b) Not flagged

$$P(S\mid F^c) = \frac{0.05\times 0.40}{1 - 0.398} = \frac{0.020}{0.602} = 0.033$$

5 in 100 spam emails are missed, and no flag has chance 0.602

Answer $$\boxed{P(S\mid F)\approx 0.955,\qquad P(S\mid F^c)\approx 0.033}$$
Check

Total probability in reverse: $0.955\times 0.398 + 0.033\times 0.602 = 0.380 + 0.020 = 0.400$, which is $P(S)$ again.

With a common class, 40 in 100, a flag is trustworthy; the same filter on a rare class would not be. Base rates decide.

3§01.4 — labelling errors, binomial against Poisson

An annotation vendor labels 1,500 images, and each label is wrong with probability 0.002, independently of the others. Let $X$ be the number of wrong labels.

Find
  1. (a) Find $P(X = 0)$ exactly and with the Poisson approximation.

  2. (b) Find $P(X\le 2)$ with the Poisson approximation.

Given
  • $n = 1{,}500$

  • $p = 0.002$

  • labels independent

Hint 1/4

Name the exact model first, then its shortcut: many tries with a small chance each is the setting of the law of rare events.

Hint 2/4

$X\sim\mathrm{Binomial}(n,p)$, and $X\approx\mathrm{Poisson}(\lambda)$ with $\lambda = np$, where $P(X = y) = e^{-\lambda}\lambda^y/y!$.

Hint 3/4

$\lambda = 1{,}500\times 0.002 = 3$; exact $P(X = 0) = 0.998^{1500}$; Poisson $P(X = 0) = e^{-3}$ and $P(X\le 2) = e^{-3}(1 + 3 + 4.5)$.

Hint 4/4

So $P(X = 0)$ is $0.0496$ exactly and $0.0498$ by Poisson, and $P(X\le 2)\approx 0.423$.

Show solution

Set $\lambda = np$ first; every Poisson number then comes from one exponential.

Model and rate

$$X\sim\mathrm{Binomial}(1500,\ 0.002),\qquad \lambda = np = 3$$

independent labels with the same error chance

(a) No errors

$$0.998^{1500} = e^{1500\ln 0.998} = e^{-3.003} = 0.0496$$

exact binomial

$$e^{-3} = 0.0498$$

Poisson

(b) At most two errors

$$e^{-3}\big(1 + 3 + \tfrac{3^2}{2}\big) = 8.5e^{-3} = 0.423$$

the first three Poisson terms

Answer $$\boxed{P(X = 0)\approx 0.050,\qquad P(X\le 2)\approx 0.423}$$
Check

The exact binomial sum for (b) is 0.42297, against the Poisson 0.42319. In (a) the two answers differ only through the 0.003 in the exponent.

When $n$ is large and $p$ small, use the Poisson with $\lambda = np$; its error is far below the precision you need.

4§01.5 — mean and variance of a continuous score

A normalised anomaly score $Y$ has pdf $f_Y(y) = 3y^2$ for $0\le y\le 1$ and 0 elsewhere. Scores near 1 are treated as suspicious.

Find
  1. (a) Find $E[Y]$.

  2. (b) Find $\operatorname{Var}(Y)$.

  3. (c) Find $P(Y > 0.5)$.

Given$f_Y(y) = 3y^2$ on $[0,1]$
Hint 1/4

Every quantity is an integral against the density; do the three integrals separately and keep fractions.

Hint 2/4

$E[g(Y)] = \int_0^1 g(y)\,3y^2\,dy$, $\operatorname{Var}(Y) = E[Y^2] - E[Y]^2$ and $P(Y > 0.5) = \int_{0.5}^{1}3y^2\,dy$.

Hint 3/4

$E[Y] = \int_0^1 3y^3\,dy = \tfrac34$, $E[Y^2] = \int_0^1 3y^4\,dy = \tfrac35$, and $\int_{0.5}^{1}3y^2\,dy = 1 - 0.5^3$.

Hint 4/4

So $E[Y] = 0.75$, $\operatorname{Var}(Y) = \tfrac35 - \tfrac9{16} = \tfrac3{80} = 0.0375$ and $P(Y > 0.5) = 0.875$.

Show solution

Use the variance shortcut and the CDF; both reduce everything to power-rule integrals.

Mean

$$E[Y] = \int_0^1 y\cdot 3y^2\,dy = \tfrac34$$

power rule

Variance

$$E[Y^2] = \int_0^1 3y^4\,dy = \tfrac35$$

power rule again

$$\operatorname{Var}(Y) = \tfrac35 - \big(\tfrac34\big)^2 = \tfrac{48 - 45}{80} = \tfrac3{80}$$

shortcut formula

Tail probability

$$P(Y > 0.5) = 1 - F_Y(0.5) = 1 - 0.5^3 = 0.875$$

the CDF is $F_Y(y) = y^3$

Answer $$\boxed{E[Y] = 0.75,\quad \operatorname{Var}(Y) = 0.0375,\quad P(Y > 0.5) = 0.875}$$
Check

The density grows like y squared, so the mass piles up near 1: a mean of 0.75 and 7 in 8 of the mass above 0.5 fit. The standard deviation, 0.19, is below 0.5, as it must be on [0, 1].

For densities $(k+1)y^k$ on $[0,1]$ the mean is $(k+1)/(k+2)$; the pattern checks both this answer and the $2s$ example.

5§01.6 — variances of sums of two features

Two features have $\operatorname{Var}(X_1) = 4$, $\operatorname{Var}(X_2) = 9$ and $\operatorname{Cov}(X_1, X_2) = -3$. A model uses their sum, their difference and their average.

Find
  1. (a) Find $\operatorname{Var}(X_1 + X_2)$.

  2. (b) Find $\operatorname{Var}(X_1 - X_2)$.

  3. (c) Find $\operatorname{Var}\big(\tfrac{X_1 + X_2}{2}\big)$.

Given$\Sigma = \begin{bmatrix}4 & -3\\ -3 & 9\end{bmatrix}$
Hint 1/4

Each quantity is a weighted sum $a^TX$, so one formula covers all three; only the weights change.

Hint 2/4

$\operatorname{Var}(a^TX) = a^T\Sigma a = a_1^2\Sigma_{11} + 2a_1a_2\Sigma_{12} + a_2^2\Sigma_{22}$.

Hint 3/4

With $\Sigma_{11} = 4$, $\Sigma_{22} = 9$, $\Sigma_{12} = -3$: weights $(1,1)$ give $4 - 6 + 9$, weights $(1,-1)$ give $4 + 6 + 9$, and weights $(\tfrac12,\tfrac12)$ give $\tfrac14(4 - 6 + 9)$.

Hint 4/4

So the three variances are 7, 19 and 1.75.

Show solution

Write $a^T\Sigma a$ out once with general weights; each part is then a substitution.

One formula

$$\operatorname{Var}(a_1X_1 + a_2X_2) = 4a_1^2 + 2(-3)a_1a_2 + 9a_2^2$$

$a^T\Sigma a$ written out

Three choices of weights

$$a = (1,1):\ 4 - 6 + 9 = 7$$

the sum

$$a = (1,-1):\ 4 + 6 + 9 = 19$$

the difference

$$a = (\tfrac12,\tfrac12):\ \tfrac14\times 7 = 1.75$$

halving the sum divides its variance by 4

Answer $$\boxed{7,\qquad 19,\qquad 1.75}$$
Check

Consistency: $\operatorname{Var}(X_1 + X_2) + \operatorname{Var}(X_1 - X_2) = 2(4 + 9) = 26$, and $7 + 19 = 26$.

Covariance is what separates the variance of a sum from the sum of the variances; with independent features all three answers would use a covariance of 0.

6§01.7 — the bound at n = 500, then the size for 1 in 100

A fixed classifier is tested on 500 images drawn independently. The team wants to know how far the measured error might stray, and how many images a tighter promise would need.

Find
  1. (a) Evaluate Hoeffding's bound on $P(\vert\hat R_{500} - R\vert\ge 0.04)$.

  2. (b) Find the smallest $n$ that makes this bound at most $0.01$.

Given
  • $n = 500$

  • tolerance $\varepsilon = 0.04$

  • target failure chance $\delta = 0.01$

Hint 1/4

Part (a) plugs numbers in; part (b) runs the same inequality backwards, with n as the unknown.

Hint 2/4

$P(\vert\hat R_n - R\vert\ge\varepsilon)\le 2e^{-2n\varepsilon^2}$, and $2e^{-2n\varepsilon^2}\le\delta\iff n\ge\ln(2/\delta)/(2\varepsilon^2)$.

Hint 3/4

(a) $2n\varepsilon^2 = 2\times 500\times 0.0016 = 1.6$. (b) $\ln(2/0.01) = \ln 200 = 5.298$ and $2\varepsilon^2 = 0.0032$.

Hint 4/4

So (a) $2e^{-1.6} = 0.404$ and (b) $n\ge 1655.7$, so 1,656 images.

Show solution

Compute the exponent on its own line in both parts; it is the only place a slip can hide.

(a) Plug in

$$2n\varepsilon^2 = 2\times 500\times 0.04^2 = 1.6$$

the exponent

$$2e^{-1.6} = 0.404$$

the bound

(b) Solve for n

$$n\ge\frac{\ln 200}{2\times 0.04^2} = \frac{5.298}{0.0032} = 1655.7$$

logarithm of both sides

$$n = 1{,}656$$

round up

Answer $$\boxed{\text{(a) } 0.404\qquad \text{(b) } n = 1{,}656}$$
Check

Plug 1,656 back in: $2e^{-2\times 1656\times 0.0016} = 2e^{-5.299} = 0.00999\le 0.01$, while 1,655 gives 0.01002.

At 500 images the guarantee is weak, about 4 in 10; a little over three times as many images bring it to 1 in 100, because the bound falls exponentially.

7§01.5 — classes that never appear in a batch

A training batch of 10 images is drawn with replacement from a dataset with 10 equally common classes. Some classes may not appear in the batch at all.

Find(a) Find the expected number of classes that do not appear in the batch.
Given
  • 10 classes, each with chance 1/10 on every draw

  • 10 independent draws

Hint 1/4

The number of missing classes has an awkward pmf, but it is a sum over the classes of 'is this class missing?'.

Hint 2/4

$N = \sum_{k=1}^{10}I(\text{class } k \text{ missing})$, so $E[N] = \sum_k P(\text{class } k \text{ missing})$.

Hint 3/4

A given class is missed by one draw with chance $0.9$, and by all 10 independent draws with chance $0.9^{10} = 0.3487$.

Hint 4/4

So $E[N] = 10\times 0.3487\approx 3.49$ classes.

Show solution

Sum indicators, one per class; the exact pmf of the count is not needed for its mean.

Indicators, one per class

$$N = \sum_{k=1}^{10}I(A_k),\qquad A_k = \{\text{class } k \text{ never drawn}\}$$

a count written as a sum of indicators

One probability

$$P(A_k) = 0.9^{10} = 0.3487$$

each independent draw misses class k with chance 0.9

Add

$$E[N] = 10\times 0.3487 = 3.49$$

linearity; the indicators are dependent, and it does not matter

Answer $$\boxed{E[N]\approx 3.49}$$
Check

Range check: between 0 and 9 classes can be missing, since 10 draws always show at least one class, and 3.49 lies inside; for a batch of $m$ draws the answer $10\times 0.9^m$ goes to 0 as $m$ grows.

Whenever a count's pmf is messy, sum indicators; dependence between them never affects the mean.

8§01.6 — revenue as a product of independent variables

In a click model, $X$ is the number of ads a visitor clicks: 0, 1 or 2 with chances 0.5, 0.3 and 0.2. $Y$ is the revenue per click in lira, independent of $X$, with $E[Y] = 3$ and $\operatorname{Var}(Y) = 4$. The revenue from one visit is $XY$.

Find
  1. (a) Find the expected revenue $E[XY]$.

  2. (b) Find $\operatorname{Var}(XY)$.

Given
  • $P(X = 0) = 0.5$, $P(X = 1) = 0.3$, $P(X = 2) = 0.2$

  • $E[Y] = 3$, $\operatorname{Var}(Y) = 4$

  • $X$ and $Y$ independent

Hint 1/4

Both answers are expectations of a function of $X$ times a function of $Y$, and the two are independent; the joint pmf is never needed.

Hint 2/4

$X, Y$ independent $\Rightarrow E[g(X)h(Y)] = E[g(X)]\,E[h(Y)]$, and $\operatorname{Var}(XY) = E[X^2Y^2] - (E[XY])^2$.

Hint 3/4

$E[X] = 0.3 + 2(0.2) = 0.7$ and $E[X^2] = 0.3 + 4(0.2) = 1.1$; $E[Y] = 3$ and $E[Y^2] = 4 + 3^2 = 13$.

Hint 4/4

So $E[XY] = 0.7\times 3 = 2.1$ lira and $\operatorname{Var}(XY) = 1.1\times 13 - 2.1^2 = 9.89$.

Show solution

Factorise every expectation with independence: two one-variable moments of each factor replace a joint table that is not given.

Moments of each factor

$$E[X] = 0.7,\qquad E[X^2] = 0\cdot 0.5 + 1\cdot 0.3 + 4\cdot 0.2 = 1.1$$

weighted sums over the pmf of X

$$E[Y^2] = \operatorname{Var}(Y) + E[Y]^2 = 4 + 9 = 13$$

the variance shortcut read backwards

Mean of the product

$$E[XY] = E[X]\,E[Y] = 0.7\times 3 = 2.1$$

independence with $g(x) = x$, $h(y) = y$

Variance of the product

$$E[X^2Y^2] = E[X^2]\,E[Y^2] = 1.1\times 13 = 14.3$$

independence again, now with $g(x) = x^2$, $h(y) = y^2$

$$\operatorname{Var}(XY) = 14.3 - 2.1^2 = 9.89$$

variance shortcut applied to the variable $XY$

Answer $$\boxed{E[XY] = 2.1,\qquad \operatorname{Var}(XY) = 9.89}$$
Check

Second route, from the variances: $\operatorname{Var}(X) = 1.1 - 0.49 = 0.61$. For independent factors, $\operatorname{Var}(XY) = \sigma_X^2\sigma_Y^2 + \sigma_X^2E[Y]^2 + \sigma_Y^2E[X]^2$. That is $0.61(4) + 0.61(9) + 4(0.49) = 9.89$.

Independence lets you factor the expectation of any product $g(X)h(Y)$, not only $XY$; that turns a question about a pair into two questions about one variable each.

9§01.5 — mean and variance of a Poisson count

The number of failed requests a server logs in one minute is modelled as $X\sim\mathrm{Poisson}(\lambda)$, with $P(X = y) = e^{-\lambda}\lambda^y/y!$ for $y = 0, 1, 2, \dots$ The table of families lists its mean and variance as both $\lambda$; here you derive them.

Find
  1. (a) Show that $E[X] = \lambda$.

  2. (b) Show that $E[X(X-1)] = \lambda^2$, and deduce $\operatorname{Var}(X) = \lambda$.

  3. (c) Give the mean and standard deviation of the count for $\lambda = 2$.

Given
  • $p_X(y) = e^{-\lambda}\lambda^y/y!$ for $y = 0, 1, 2, \dots$

  • $\sum_{k\ge 0}\lambda^k/k! = e^{\lambda}$

Hint 1/4

In each sum the factor $y$ or $y(y-1)$ cancels against the start of $y!$; what is left is again a Poisson pmf summed over all its values.

Hint 2/4

$\sum_{k\ge 0}e^{-\lambda}\lambda^k/k! = 1$, and $\operatorname{Var}(X) = E[X(X-1)] + E[X] - E[X]^2$.

Hint 3/4

$E[X] = \lambda\sum_{y\ge 1}e^{-\lambda}\lambda^{y-1}/(y-1)!$ and $E[X(X-1)] = \lambda^2\sum_{y\ge 2}e^{-\lambda}\lambda^{y-2}/(y-2)!$. For (c), $\lambda = 2$.

Hint 4/4

So $E[X] = \lambda$, $E[X(X-1)] = \lambda^2$ and $\operatorname{Var}(X) = \lambda^2 + \lambda - \lambda^2 = \lambda$; for $\lambda = 2$ the mean is 2 failures and the standard deviation $\sqrt2\approx 1.41$.

Show solution

Compute $E[X(X-1)]$ rather than $E[X^2]$: the factor $y(y-1)$ cancels cleanly against $y!$, while $y^2$ does not.

Mean by shifting the index

$$E[X] = \sum_{y\ge 1} y\,\frac{e^{-\lambda}\lambda^y}{y!} = \lambda\sum_{y\ge 1}\frac{e^{-\lambda}\lambda^{y-1}}{(y-1)!}$$

the $y = 0$ term is zero, and $y/y! = 1/(y-1)!$

$$= \lambda\sum_{k\ge 0}\frac{e^{-\lambda}\lambda^{k}}{k!} = \lambda$$

with $k = y - 1$ the sum is a Poisson pmf over all its values, so it equals 1

Factorial moment

$$E[X(X-1)] = \sum_{y\ge 2} y(y-1)\frac{e^{-\lambda}\lambda^y}{y!} = \lambda^2\sum_{k\ge 0}\frac{e^{-\lambda}\lambda^{k}}{k!} = \lambda^2$$

terms $y = 0, 1$ vanish, $y(y-1)/y! = 1/(y-2)!$, then $k = y - 2$

Variance

$$E[X^2] = E[X(X-1)] + E[X] = \lambda^2 + \lambda$$

linearity, since $X^2 = X(X-1) + X$

$$\operatorname{Var}(X) = \lambda^2 + \lambda - \lambda^2 = \lambda$$

variance shortcut $E[X^2] - E[X]^2$

Numbers for λ = 2

$$E[X] = 2,\qquad \sigma_X = \sqrt2\approx 1.41$$

standard deviation is the square root of the variance

Answer $$\boxed{E[X] = \operatorname{Var}(X) = \lambda;\quad \lambda = 2:\ 2\ \text{and}\ \sigma\approx 1.41}$$
Check

Numeric check for $\lambda = 2$: summing $y\,p_X(y)$ and $y^2p_X(y)$ over $y = 0,\dots,39$ gives 2.0000 and 6.0000, so the variance is $6 - 4 = 2$. It also matches the binomial limit: $np(1-p)\to\lambda$ as $p\to 0$ with $np = \lambda$.

For count data, compare the sample mean with the sample variance: a Poisson model needs them to be about equal.

C · exam level 4 questions
1§01.3 — two screening tests in a row

A factory screens components in two stages; 1 in 200 is defective. Test A flags 95 of every 100 defective and 4 of every 100 good components. Those flagged go to test B, which flags 90 of every 100 defective and 1 of every 100 good ones, independently of A given the true state.

Find
  1. (a) Find the chance that a component flagged by A is defective.

  2. (b) Find the chance that a component flagged by both A and B is defective.

Given
  • $P(D) = 0.005$

  • test A: $P(F_A\mid D) = 0.95$, $P(F_A\mid G) = 0.04$

  • test B: $P(F_B\mid D) = 0.90$, $P(F_B\mid G) = 0.01$

  • A and B independent given the true state

Hint 1/4

Run Bayes' rule twice: the answer to (a) becomes the prior for (b), because B only sees components that A flagged.

Hint 2/4

Each stage uses $$\text{posterior} = \frac{\text{hit rate}\times\text{prior}}{\text{hit rate}\times\text{prior} + \text{false alarm rate}\times(1 - \text{prior})}.$$

Hint 3/4

(a) $\frac{0.95\times 0.005}{0.95\times 0.005 + 0.04\times 0.995} = \frac{0.00475}{0.04455}$. (b) $\frac{0.90\times 0.1066}{0.90\times 0.1066 + 0.01\times 0.8934}$.

Hint 4/4

So (a) is about 0.107 and (b) is about 0.915.

Show solution

Update in two stages rather than in one big formula: the intermediate answer is itself asked for, and it becomes the prior for stage B.

Stage A

$$P(D\mid F_A) = \frac{0.95\times 0.005}{0.95\times 0.005 + 0.04\times 0.995} = \frac{0.00475}{0.04455} = 0.1066$$

Bayes' rule with the factory prior

Stage B, with stage A's posterior as the prior

$$P(D\mid F_A, F_B) = \frac{0.90\times 0.1066}{0.90\times 0.1066 + 0.01\times 0.8934} = \frac{0.0960}{0.1049} = 0.915$$

B is independent of A given the state, so only its own rates enter

Answer $$\boxed{P(D\mid F_A)\approx 0.107,\qquad P(D\mid F_A, F_B)\approx 0.915}$$
Check

One-shot route, the same number: $$\frac{0.005\times 0.95\times 0.90}{0.005\times 0.95\times 0.90 + 0.995\times 0.04\times 0.01} = \frac{0.004275}{0.004673} = 0.915.$$

Yesterday's posterior is today's prior: independent pieces of evidence can be absorbed one at a time.

2§01.6 — mean and variance of a binomial count

A test set has $n$ images, and a fixed classifier errs on each one independently with probability $p$. The number of errors is $X = \sum_{i=1}^{n}I_i$, where $I_i$ is 1 if image $i$ is misclassified.

Find
  1. (a) Show that $E[X] = np$.

  2. (b) Show that $\operatorname{Var}(X) = np(1-p)$.

  3. (c) Evaluate both for $n = 400$ and $p = 0.09$.

Given
  • $I_1,\dots,I_n$ independent, with $P(I_i = 1) = p$

  • $X = \sum_i I_i\sim\mathrm{Binomial}(n,p)$

Hint 1/4

Work with the indicators, not with the binomial pmf: sums of simple pieces are easier than a sum over binomial coefficients.

Hint 2/4

$E[\sum I_i] = \sum E[I_i]$ always, while $\operatorname{Var}(\sum_i I_i)$ equals $\sum_i\operatorname{Var}(I_i) + 2\sum_{i<j}\operatorname{Cov}(I_i, I_j)$.

Hint 3/4

$E[I_i] = p$; since $I_i^2 = I_i$, $\operatorname{Var}(I_i) = p - p^2$; independence gives $\operatorname{Cov}(I_i, I_j) = 0$. For the numbers: $n = 400$, $p = 0.09$.

Hint 4/4

So $E[X] = np$ and $\operatorname{Var}(X) = np(1-p)$, which are 36 and 32.76 for this test set.

Show solution

Indicators turn both moments into sums of identical simple terms; the binomial pmf would need sums of binomial coefficients.

Mean

$$E[X] = \sum_{i=1}^{n}E[I_i] = \sum_{i=1}^{n}p = np$$

linearity and the indicator rule

Variance of one indicator

$$I_i^2 = I_i\ \Rightarrow\ E[I_i^2] = p$$

0 and 1 are their own squares

$$\operatorname{Var}(I_i) = p - p^2 = p(1-p)$$

shortcut formula

Variance of the sum

$$\operatorname{Var}(X) = \sum_i\operatorname{Var}(I_i) + 2\sum_{i<j}\operatorname{Cov}(I_i, I_j)$$

expand $E[(X - np)^2]$ with $X - np = \sum_i(I_i - p)$

$$= np(1-p) + 0$$

independent indicators have zero covariance

Numbers

$$np = 36,\qquad np(1-p) = 400\times 0.09\times 0.91 = 32.76$$

n = 400, p = 0.09

Answer $$\boxed{E[X] = np = 36,\qquad \operatorname{Var}(X) = np(1-p) = 32.76}$$
Check

The case n = 1 gives back the Bernoulli entries of the table: mean p and variance p(1 − p), exactly as the formulas say.

Means of sums never need independence; variances of sums need the covariances, and independence is what sets them to zero.

3§01.7 — the tolerance a test set of 1,000 can promise

A team has exactly 1,000 held-out images for a fixed classifier, and wants to state: the true error is within ε of the measured error, except with chance at most 0.05.

Find(a) What is the smallest $\varepsilon$ that Hoeffding's inequality supports?
Given
  • $n = 1{,}000$

  • $\delta = 0.05$

  • indicators independent, each 0 or 1

Hint 1/4

This time n is fixed and the tolerance is the unknown: run the sample-size inequality the other way round.

Hint 2/4

$2e^{-2n\varepsilon^2}\le\delta\iff\varepsilon\ge\sqrt{\dfrac{\ln(2/\delta)}{2n}}$.

Hint 3/4

With $n = 1{,}000$ and $\delta = 0.05$: $\sqrt{\ln 40/2{,}000} = \sqrt{3.689/2{,}000}$.

Hint 4/4

So $\varepsilon\approx 0.043$.

Show solution

Set the bound equal to δ and solve for ε; any smaller tolerance would push the bound above δ.

Solve for the tolerance

$$2e^{-2n\varepsilon^2} = \delta\iff\varepsilon = \sqrt{\frac{\ln(2/\delta)}{2n}}$$

equality gives the smallest supported tolerance

Numbers

$$\varepsilon = \sqrt{\frac{\ln 40}{2{,}000}} = \sqrt{0.001844} = 0.0429$$

$\ln 40 = 3.689$

Answer $$\boxed{\varepsilon\approx 0.043}$$
Check

Plug back in: $2e^{-2\times 1000\times 0.043^2} = 2e^{-3.698} = 0.0495\le 0.05$, while a tolerance of 0.042 would give 0.059.

The tolerance shrinks like $1/\sqrt n$: four times the test set halves the tolerance you can promise.

4§01.4 — Gaussian label noise

Labels follow $Y = f(X) + \omega$ with $\omega\sim N(0, 0.25)$, independent of $X$. A prediction equal to the true $f(X)$ is called badly off if it misses $Y$ by more than 1.

Find
  1. (a) Find the chance that even the true function is badly off on a new pair.

  2. (b) What noise variance would make that chance exactly 0.05?

Given
  • $\omega\sim N(0, 0.25)$

  • for $Z\sim N(0,1)$: $P(\vert Z\vert > 2) = 0.0455$ and $P(\vert Z\vert > 1.96) = 0.05$

Hint 1/4

The true function misses Y by exactly the noise, so the question is about ω alone; turn it into a question about a standard normal.

Hint 2/4

If $\omega\sim N(0,\sigma^2)$ then $\omega/\sigma\sim N(0,1)$, so $P(\vert\omega\vert > c) = P(\vert Z\vert > c/\sigma)$. The second parameter is the variance.

Hint 3/4

Variance 0.25 means $\sigma = 0.5$, so $P(\vert\omega\vert > 1) = P(\vert Z\vert > 2)$. For (b), require $1/\sigma = 1.96$.

Hint 4/4

So (a) is 0.0455, and (b) needs $\sigma = 0.510$, a variance of 0.260.

Show solution

Divide by the standard deviation to reach the standard normal, where the tail values are known.

Standardise

$$\sigma = \sqrt{0.25} = 0.5,\qquad P(\vert\omega\vert > 1) = P\big(\vert Z\vert > \tfrac{1}{0.5}\big) = P(\vert Z\vert > 2)$$

divide by the standard deviation, not by the variance

(a) Read the tail

$$P(\vert Z\vert > 2) = 0.0455$$

given value

(b) Solve for the variance

$$\frac{1}{\sigma} = 1.96\ \Rightarrow\ \sigma = 0.5102,\qquad \sigma^2 = 0.2603$$

$P(\vert Z\vert > 1.96) = 0.05$

Answer $$\boxed{\text{(a) } 0.0455\qquad \text{(b) } \sigma^2\approx 0.260}$$
Check

Direction check: 5 in 100 is a little looser than 4.55 in 100, so the noise may be a little larger than 0.25, and 0.260 is.

Noise puts a floor under the error of every rule, the true one included; no amount of training data removes it.

D · interleaved 4 questions
1§01.0 — how many errors to expect, and how far they spread

Mixed practice; the type is not announced. A classifier with true error rate 0.09 is run on 400 independent test images, and someone later reports a measured error of 0.14 for it.

Find
  1. (a) Find the mean and the variance of the number of errors $N$.

  2. (b) Find the standard deviation of the measured error rate $N/400$.

  3. (c) How many standard deviations above the true rate is 0.14?

Given
  • true error 0.09 per image, images independent

  • $n = 400$

  • reported measured error 0.14

Hint 1/4

Identify the distribution of N first; each part then follows from one formula.

Hint 2/4

$N\sim\mathrm{Binomial}(n,p)$: $E[N] = np$, $\operatorname{Var}(N) = np(1-p)$, and $\operatorname{Var}(N/n) = p(1-p)/n$.

Hint 3/4

With $n = 400$ and $p = 0.09$: $np = 36$, $np(1-p) = 32.76$ and $\sqrt{0.09\times 0.91/400} = 0.0143$.

Hint 4/4

So the mean is 36, the variance 32.76, the rate's standard deviation 0.0143, and 0.14 sits $(0.14 - 0.09)/0.0143\approx 3.5$ standard deviations above.

Show solution

Recognise the binomial first: independent images with a common error chance; after that every part is one formula.

(a) Mean and variance

$$E[N] = 400\times 0.09 = 36,\qquad \operatorname{Var}(N) = 400\times 0.09\times 0.91 = 32.76$$

binomial formulas

(b) Scale to a rate

$$\operatorname{sd}(N/400) = \frac{\sqrt{32.76}}{400} = \frac{5.72}{400} = 0.0143$$

dividing N by 400 divides its standard deviation by 400

(c) Standardise

$$\frac{0.14 - 0.09}{0.0143} = 3.49$$

distance from the mean in standard deviations

Answer $$\boxed{36,\quad 32.76,\quad 0.0143,\quad 3.5\ \text{standard deviations}}$$
Check

Exact binomial tail: $P(N\ge 56) = 0.00068$, so a measured 0.14 would be about a 7 in 10,000 event. The bell curve's value at 3.5 standard deviations, 0.0002, understates it at this $n$, but both say rare.

On a 400-image test set, 0.014 is the natural unit for judging a reported error rate.

2§01.0 — which machine, given a defect count

Mixed practice; the type is not announced. A randomly chosen hour of production comes from machine 1 with probability 0.6 and from machine 2 with probability 0.4. In an hour, defects follow a Poisson distribution with mean 2 on machine 1 and mean 5 on machine 2. The chosen hour shows exactly 4 defects.

Find(a) Find the probability that the hour came from machine 1.
Given
  • $P(M_1) = 0.6$, $P(M_2) = 0.4$

  • defects: $\mathrm{Poisson}(2)$ on $M_1$, $\mathrm{Poisson}(5)$ on $M_2$

  • observed: 4 defects

Hint 1/4

This is a which-cause question given evidence; the chances of the evidence come from a named distribution.

Hint 2/4

$P(M_1\mid 4) = \dfrac{P(4\mid M_1)P(M_1)}{P(4\mid M_1)P(M_1) + P(4\mid M_2)P(M_2)}$ with $P(4\mid\lambda) = e^{-\lambda}\lambda^4/4!$.

Hint 3/4

$P(4\mid M_1) = e^{-2}2^4/24 = 0.0902$ and $P(4\mid M_2) = e^{-5}5^4/24 = 0.1755$, with priors 0.6 and 0.4.

Hint 4/4

So $P(M_1\mid 4) = 0.0541/(0.0541 + 0.0702)\approx 0.435$.

Show solution

Get the two likelihoods from the Poisson pmf first; Bayes' rule is then the same two-branch calculation as the fraud detector.

Likelihoods from the Poisson pmf

$$P(4\mid M_1) = \frac{e^{-2}2^4}{4!} = 0.0902,\qquad P(4\mid M_2) = \frac{e^{-5}5^4}{4!} = 0.1755$$

Poisson pmf at 4

Bayes' rule

$$P(M_1\mid 4) = \frac{0.6\times 0.0902}{0.6\times 0.0902 + 0.4\times 0.1755} = \frac{0.0541}{0.1243} = 0.435$$

prior times likelihood, normalised over both machines

Answer $$\boxed{P(M_1\mid 4\ \text{defects})\approx 0.435}$$
Check

Odds form: prior odds 0.6/0.4 = 1.5, likelihood ratio 0.0902/0.1755 = 0.514, posterior odds 0.771, and 0.771/1.771 = 0.435.

Named distributions supply the likelihoods and Bayes' rule does the rest; the structure never changes.

3§01.0 — a combined feature and its covariance

Mixed practice; the type is not announced. Two features $X_1$ and $X_2$ are independent, each with mean 3 and variance 2. A model builds the combined feature $S = 2X_1 - X_2 + 1$.

Find
  1. (a) Find $E[S]$.

  2. (b) Find $\operatorname{Var}(S)$.

  3. (c) Find $\operatorname{Cov}(S, X_1)$.

Given
  • $X_1, X_2$ independent

  • $E[X_i] = 3$, $\operatorname{Var}(X_i) = 2$

  • $S = 2X_1 - X_2 + 1$

Hint 1/4

Three different tools: linearity for the mean, the covariance matrix for the variance, and linearity of covariance in each argument for the last part.

Hint 2/4

$E[S] = 2E[X_1] - E[X_2] + 1$; $\operatorname{Var}(a^TX) = a^T\Sigma a$; $\operatorname{Cov}(aX_1 + bX_2 + c, X_1) = a\operatorname{Var}(X_1) + b\operatorname{Cov}(X_2, X_1)$.

Hint 3/4

Means 3 and 3, variances 2 and 2, $\operatorname{Cov}(X_1, X_2) = 0$ by independence, and weights $a = (2, -1)$.

Hint 4/4

So $E[S] = 4$, $\operatorname{Var}(S) = 4(2) + 1(2) = 10$ and $\operatorname{Cov}(S, X_1) = 2\times 2 = 4$.

Show solution

Write the covariance matrix down first; independence makes it diagonal, and every later step reads from it.

Mean

$$E[S] = 2(3) - 3 + 1 = 4$$

linearity

Variance

$$\Sigma = \begin{bmatrix}2 & 0\\ 0 & 2\end{bmatrix},\quad a = (2,-1):\quad a^T\Sigma a = 4(2) + 1(2) = 10$$

independence zeroes the off-diagonal; the constant 1 adds nothing

Covariance with the first feature

$$\operatorname{Cov}(S, X_1) = 2\operatorname{Var}(X_1) - \operatorname{Cov}(X_2, X_1) = 4 - 0 = 4$$

covariance is linear in each argument

Answer $$\boxed{E[S] = 4,\quad \operatorname{Var}(S) = 10,\quad \operatorname{Cov}(S, X_1) = 4}$$
Check

Size check: in size, a covariance is at most the product of the standard deviations, $\sqrt{10}\times\sqrt2 = 4.47$, and 4 is below it.

Linearity gives means for free; for variances, write the covariance matrix down and let $a^T\Sigma a$ do the bookkeeping.

4§01.0 — one test set, five classifiers, one promise

Mixed practice; the type is not announced. Five classifiers, all fixed before testing, are evaluated on the same test set of n independent images. The team wants all five measured errors within 0.05 of their true errors at once, except with total chance at most 0.05.

Find(a) How large must n be?
Given
  • 5 fixed classifiers, one shared test set

  • tolerance $\varepsilon = 0.05$ for each

  • total failure chance $\delta = 0.05$

Hint 1/4

The failure event is 'at least one of the five misses', a union. The five misses share images, so they are dependent: bound, do not compute.

Hint 2/4

Union bound: $P(\cup_{k=1}^{5}B_k)\le\sum_k P(B_k)$, and Hoeffding gives each $P(B_k)\le 2e^{-2n\varepsilon^2}$.

Hint 3/4

Require $5\times 2e^{-2n(0.05)^2}\le 0.05$, that is $2e^{-0.005n}\le 0.01$, so $n\ge\ln(200)/0.005$.

Hint 4/4

So $n\ge 1059.7$, and 1,060 images are needed.

Show solution

Bound each classifier with Hoeffding and join them with the union bound; the dependence between the five is unknown and never needed.

Name the failure events

$$B_k = \{\vert\hat R_n(f_k) - R(f_k)\vert\ge 0.05\},\qquad \text{fail} = \textstyle\bigcup_{k=1}^{5}B_k$$

one miss event per classifier

Bound each, then the union

$$P(B_k)\le 2e^{-2n(0.05)^2}$$

Hoeffding for each fixed classifier

$$P(\text{fail})\le 5\times 2e^{-2n(0.05)^2}$$

union bound, with no need to know how the misses depend on each other

Solve

$$10e^{-0.005n}\le 0.05\iff n\ge\frac{\ln 200}{0.005} = 1059.7$$

divide by 10 and take logarithms

$$n = 1{,}060$$

round up

Answer $$\boxed{n = 1{,}060}$$
Check

Plug back in: $10e^{-0.005\times 1060} = 10e^{-5.3} = 0.0499\le 0.05$. Against one classifier, $\ln 200/\ln 40 = 1.44$, so 44 more images in every 100 buy the promise for all five.

Testing $k$ fixed rules on one test set adds only a $\ln k$ term to the required size, as long as the rules are fixed before the test set is drawn.

Mistake ledger (19 entries)
⚠ Reporting training error as the performance

it is the only error you can compute without holding data back, and a small number looks like good news

wrong$$\text{training error} = 0\ \Rightarrow\ \text{error on new data}\approx 0$$
right$$\text{error on new data is measured on examples not used for training}$$
⚠ Expecting the right rule to pass through every training point

fitting the data exactly feels like the goal of learning

wrong$$\hat f(x_i) = y_i \ \text{for all } i \ \text{is the aim}$$
right$$y_i = f(x_i) + \omega_i:\ \text{even } \hat f = f \text{ misses by } \omega_i$$
⚠ Counting unequal outcomes as if they were equally likely

'number of cats' has four values, and it is tempting to give each value a quarter

wrong$$P(\text{exactly two cats}) = \tfrac14$$
right$$P(\text{exactly two cats}) = \tfrac38$$
⚠ Adding the chances of events that overlap

(A3) looks like a general rule for unions, but it only applies to disjoint events

wrong$$P(A\cup B) = P(A) + P(B)$$
right$$P(A\cup B) = P(A) + P(B) - P(A\cap B)\le P(A) + P(B)$$
⚠ Reading the conditional the wrong way round

the detector is described as 'flags 99 of 100 frauds', and that is the number in front of you

wrong$$P(\text{fraud}\mid\text{flag}) = P(\text{flag}\mid\text{fraud}) = 0.99$$
right$$P(\text{fraud}\mid\text{flag}) = \frac{0.99\times 0.001}{0.02097}\approx 0.047$$
⚠ Leaving the false alarms out of the denominator

the numerator is about fraud, so it feels natural to keep only fraud terms

wrong$$P(\text{flag}) = P(\text{flag}\mid\text{fraud})\,P(\text{fraud})$$
right$$P(\text{flag}) = 0.99(0.001) + 0.02(0.999) = 0.02097$$
⚠ Treating disjoint events as independent

'they have nothing to do with each other' sounds like independence

wrong$$A\cap B = \varnothing\ \Rightarrow\ P(A\cap B) = P(A)\,P(B)$$
right$$A\cap B = \varnothing,\ P(A), P(B) > 0\ \Rightarrow\ P(A\cap B) = 0\ne P(A)\,P(B)$$
⚠ Reading a density value as a probability

both are written as a function of x and both get called 'the distribution'

wrong$$P(S = 0.9) = f_S(0.9) = 1.8$$
right$$P(S = 0.9) = 0,\qquad P(0.9\le S\le 0.91)\approx 0.018$$
⚠ Reading the level of a CDF as the pmf

the CDF is the function you were handed, and its value at 1 is right there

wrong$$P(X = 1) = F_X(1) = 0.7$$
right$$P(X = 1) = F_X(1) - F_X(1^-) = 0.7 - 0.2 = 0.5$$
⚠ Squaring the mean instead of averaging the squares

for sums, 'take the mean' and the operation can be swapped, so it feels like they always can

wrong$$E[X^2] = (E[X])^2$$
right$$E[X^2] = \operatorname{Var}(X) + (E[X])^2$$
⚠ Scaling a variance by a, or letting a shift change it

the variance gets treated like the mean, which does pick up both a and b

wrong$$\operatorname{Var}(3 - 2X) = 3 - 2\operatorname{Var}(X)$$
right$$\operatorname{Var}(3 - 2X) = (-2)^2\operatorname{Var}(X) = 4\operatorname{Var}(X)$$
⚠ Reading zero covariance as independence

'uncorrelated' and 'unrelated' sound like the same word

wrong$$\operatorname{Cov}(X,Y) = 0\ \Rightarrow\ X, Y\ \text{independent}$$
right$$X, Y\ \text{independent}\ \Rightarrow\ \operatorname{Cov}(X,Y) = 0,\ \text{not the reverse}$$
⚠ Dividing by the wrong marginal

both marginals are on the page and the formula uses only one of them

wrong$$p_{X\mid Y}(x\mid 1) = \frac{p_{XY}(x,1)}{p_X(x)}$$
right$$p_{X\mid Y}(x\mid 1) = \frac{p_{XY}(x,1)}{p_Y(1)}$$
⚠ Putting the covariance matrix in the exponent instead of its inverse

in one dimension the variance sits in a denominator, and the matrix version hides that division inside an inverse

wrong$$\exp\Big(-\tfrac12(x-\mu)^T\Sigma\,(x-\mu)\Big)$$
right$$\exp\Big(-\tfrac12(x-\mu)^T\Sigma^{-1}(x-\mu)\Big)$$
⚠ Dropping the factor 2 in front

the one-sided version has no 2, and it is easy to remember the wrong one

wrong$$P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le e^{-2n\varepsilon^2}$$
right$$P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le 2e^{-2n\varepsilon^2}$$
⚠ Using Hoeffding on data outside [0, 1] without rescaling

the inequality is quoted for [0, 1] and the range condition is easy to skip

wrong$$X_i\in[2,6]:\ P(\vert\bar X - \mu\vert\ge 0.1)\le 2e^{-2n(0.1)^2}$$
right$$Z_i = \tfrac{X_i - 2}{4}:\ P(\vert\bar X - \mu\vert\ge 0.1)\le 2e^{-2n(0.1/4)^2}$$
⚠ Rounding the sample size down

truncating a decimal is a habit, and 737.8 looks close enough to 737

wrong$$n\ge 737.8\ \Rightarrow\ n = 737$$
right$$n\ge 737.8\ \Rightarrow\ n = 738$$
⚠ Applying Hoeffding to the training error

the formula looks the same for any average of indicators, and the training error is already computed

wrong$$P\big(\vert\hat R_{\text{train}}(\hat f) - R(\hat f)\vert\ge\varepsilon\big)\le 2e^{-2n\varepsilon^2}$$
right$$\text{apply it on a test set drawn after } \hat f \text{ is fixed}$$
⚠ Reading the variance in N(µ, σ²) as a standard deviation

some software and some books put the standard deviation in that slot

wrong$$\omega\sim N(0, 0.25)\ \Rightarrow\ \sigma = 0.25$$
right$$\omega\sim N(0, 0.25)\ \Rightarrow\ \sigma = \sqrt{0.25} = 0.5$$
Formula card
Supervised learning setup
$$Y = f(X) + \omega,\qquad \hat f(X)\approx Y \ \text{on new pairs}$$

training pairs and new pairs come from the same source

Axioms of probability
$$P(A)\ge 0,\quad P(\Omega) = 1,\quad P\big(\textstyle\bigcup_i A_i\big) = \textstyle\sum_i P(A_i)$$

additivity only for pairwise disjoint events

Order property and union bound
$$A\subseteq B\Rightarrow P(A)\le P(B),\qquad P\big(\textstyle\bigcup_i A_i\big)\le\textstyle\sum_i P(A_i)$$

no independence needed

Conditional probability and independence
$$P(A\mid B) = \frac{P(A\cap B)}{P(B)},\qquad P(A\cap B) = P(A)P(B)$$

P(B) > 0; the product form is the definition of independence

Bayes' rule with total probability
$$P(A\mid B) = \frac{P(B\mid A)P(A)}{\sum_i P(B\mid A_i)P(A_i)}$$

the events A_i split the sample space

CDF, pmf and pdf
$$F_X(x) = P(X\le x),\quad p_X(x) = P(X = x),\quad f_X(x) = \tfrac{d}{dx}F_X(x)$$

pmf for discrete, pdf for continuous variables

Binomial and Poisson pmfs
$$\binom{n}{y}p^{y}(1-p)^{n-y},\qquad e^{-\lambda}\lambda^{y}/y!$$

Poisson with λ = np approximates the binomial when n is large and p small

Gaussian density
$$f_X(y) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\Big(-\frac{(y-\mu)^2}{2\sigma^2}\Big)$$

second parameter of N(µ, σ²) is the variance

Expectation and linearity
$$E[g(X)] = \textstyle\sum_x g(x)p_X(x),\qquad E[aX + bY] = aE[X] + bE[Y]$$

integral with the pdf for continuous X; linearity needs no independence

Variance shortcut and scaling
$$\operatorname{Var}(X) = E[X^2] - E[X]^2,\qquad \operatorname{Var}(aX + b) = a^2\operatorname{Var}(X)$$

finite second moment

Indicator rule
$$E[I(X\in A)] = P(X\in A)$$

always

Marginal and conditional pmf
$$p_X(x) = \textstyle\sum_y p_{XY}(x,y),\qquad p_{Y\mid X}(y\mid x) = \frac{p_{XY}(x,y)}{p_X(x)}$$

p_X(x) > 0; integrals replace sums for densities

Bayes' rule for random variables
$$p_{Y\mid X}(y\mid x) = \frac{p_{X\mid Y}(x\mid y)\,p_Y(y)}{\sum_{y'}p_{X\mid Y}(x\mid y')\,p_Y(y')}$$

a density may serve as the likelihood; an integral replaces the sum when Y is continuous

Covariance
$$\operatorname{Cov}(X,Y) = E[XY] - E[X]E[Y]$$

independent implies zero covariance, not the reverse

Independence factorises expectations
$$E[g(X)\,h(Y)] = E[g(X)]\,E[h(Y)],\qquad E[XY] = E[X]\,E[Y]$$

X and Y independent; g and h any functions with finite expectations

Covariance matrix
$$\Sigma = E\big[(X-\mu)(X-\mu)^T\big],\qquad \operatorname{Var}(a^TX) = a^T\Sigma a\ge 0$$

symmetric and positive semidefinite

Multivariate Gaussian density
$$f_X(x) = \frac{\exp\big(-\frac12(x-\mu)^T\Sigma^{-1}(x-\mu)\big)}{(2\pi)^{n/2}\vert\Sigma\vert^{1/2}}$$

Σ invertible; jointly Gaussian and uncorrelated means independent

Law of large numbers and CLT
$$\bar X_n\to E[X],\qquad \frac{\bar X_n - \mu}{\sigma/\sqrt n}\xrightarrow{d}N(0,1)$$

i.i.d.; finite mean, and finite variance for the CLT

Hoeffding's inequality
$$P\big(\vert\bar Z - E[\bar Z]\vert\ge\varepsilon\big)\le 2e^{-2n\varepsilon^2}$$

Z_i independent with 0 ≤ Z_i ≤ 1; holds for every n

Sample size and tolerance
$$n\ge\frac{\ln(2/\delta)}{2\varepsilon^2},\qquad \varepsilon = \sqrt{\frac{\ln(2/\delta)}{2n}}$$

round n up; data in [a, b] use ε = t/(b − a)

Error rate as an average
$$R(f) = E[I(f(X)\ne Y)],\qquad \hat R_n(f) = \tfrac1n\textstyle\sum_i I(f(X_i)\ne Y_i)$$

f fixed before the test pairs are drawn

Check yourself

Close the page and write down from memory:

  • the three axioms and the two properties they give for free;
  • conditional probability, Bayes' rule and its denominator;
  • how the CDF, pmf and pdf turn into each other;
  • the variance shortcut and the scaling rule;
  • why zero covariance is not independence, with an example;
  • what $a^\top \Sigma a$ is the variance of;
  • Hoeffding's inequality, its conditions and the sample-size formula.

Then reopen the page and compare; whatever is missing is your reread list.

  • Sort a task into supervised, unsupervised or reinforcement learning from its data alone, and explain why a training error of zero proves nothing?

    c-learning-setup

  • Build the sample space of a three-draw experiment, and bracket the chance of 'at least one failure' when the overlaps are unknown?

    c-probability-space

  • Compute the chance that a flagged item is really positive, with both branches in the denominator, and test two events for independence?

    c-bayes

  • Read a pmf value off a CDF, explain why a pdf may exceed 1, and use the Poisson approximation with λ = np?

    c-random-variables

  • Compute a mean and a variance from a pmf or a pdf, and find the mean of a count by summing indicators?

    c-expectation

  • Get marginals, a conditional and a covariance from a joint table, build Σ for a feature vector, and test whether a matrix can be a covariance matrix?

    c-joint-vectors

  • Evaluate Hoeffding's bound for a test set, solve it for the sample size after rescaling to [0, 1], and say why it may not be applied to training error?

    c-concentration

Glossary (46 terms)
supervised learninggözetimli öğrenme

Learning a rule from input and label pairs, so that it predicts the label of new inputs from the same source.

unsupervised learninggözetimsiz öğrenme

Learning structure, such as groups or a shorter description, from inputs that carry no labels.

reinforcement learningpekiştirmeli öğrenme

Learning to choose actions from rewards that follow them, where the learner's own actions decide what it observes.

training dataeğitim verisi

The examples an algorithm uses to build its rule. Errors measured on them describe fit, not performance on new data.

test settest kümesi

Examples kept apart from training and drawn independently, used to measure how a fixed rule does on new data.

labeletiket

The output Y attached to an input X in a training pair: the quantity a supervised learner tries to predict.

noisegürültü

The part of a label that no function of the input can predict, written ω in Y = f(X) + ω.

classifiersınıflandırıcı

A rule that maps each input to one of finitely many labels, such as spam or not spam.

sample spaceörneklem uzayı

The set Ω of all possible outcomes of an experiment.

eventolay

A subset of the sample space that we can ask the probability of.

probability measureolasılık ölçüsü

The function P that gives each event a number and obeys the three axioms.

union bound

The fact that the chance of at least one of several events is at most the sum of their chances, whatever their dependence.

conditional probabilitykoşullu olasılık

The chance of A once B is known to have happened: $P(A \cap B)$ divided by $P(B)$.

independencebağımsızlık

Two events are independent when $P(A \cap B) = P(A)P(B)$, so learning one leaves the chance of the other unchanged.

BayesBayes kuralı

Bayes' rule: the identity that turns the chance of evidence given a cause into the chance of the cause given the evidence.

priorönsel

The probability of a hypothesis before the evidence is taken into account.

likelihoodolabilirlik

The probability of the observed data under a given hypothesis or parameter value.

posteriorsonsal

The probability of a hypothesis after the evidence is taken into account; proportional to prior times likelihood.

law of total probabilitytoplam olasılık kuralı

P(B) equals the sum of P(B given A_i) times P(A_i) over events A_i that split the sample space.

random variablerastgele değişken

A function that assigns a real number to every outcome of an experiment.

CDFbirikimli dağılım fonksiyonu

Cumulative distribution function, F_X(x) = P(X ≤ x): non-decreasing, climbing from 0 to 1.

pmfolasılık kütle fonksiyonu

Probability mass function: for a discrete variable, the function giving P(X = x) for each value x.

pdfolasılık yoğunluk fonksiyonu

Probability density function: for a continuous variable, the slope of the CDF. Probabilities are areas under it, and its values may exceed 1.

binomialbinom dağılımı

The binomial distribution: the number of successes in n independent trials that each succeed with the same chance p.

PoissonPoisson dağılımı

The Poisson distribution: counts 0, 1, 2 and so on, with mean and variance both equal to λ; used for counts of rare events.

Gaussiannormal dağılım

The Gaussian or normal distribution N(µ, σ²): bell-shaped, with mean µ and variance σ².

beta distributionbeta dağılımı

A distribution on [0, 1] with density proportional to $y^{\alpha-1}(1-y)^{\beta-1}$ for two positive parameters; suited to describing an unknown proportion.

law of rare events

The approximation of Binomial(n, p) by Poisson(np) when n is large and p is small.

expectationbeklenen değer

The probability-weighted average of the values of a random variable; the balance point of its distribution.

variancevaryans

The expected squared distance of a random variable from its mean.

indicator functiongösterge fonksiyonu

A random variable equal to 1 when an event happens and 0 otherwise; its mean is the event's probability.

joint distributionortak dağılım

The probabilities of the pairs, or tuples, of values that several random variables take together.

marginalmarjinal

The distribution of one variable alone, obtained from a joint distribution by summing or integrating out the others.

conditional distributionkoşullu dağılım

The distribution of one variable given the value of another: the joint divided by the marginal of the given variable.

independent and identically distributedbağımsız ve özdeş dağılımlı

Random variables that are independent and share one distribution; written i.i.d.

covariancekovaryans

E[(X − E[X])(Y − E[Y])]: a measure of how two variables move together along a straight line.

uncorrelatedilintisiz

Having zero covariance. Weaker than independence, except for jointly Gaussian variables.

random vectorrastgele vektör

A column of random variables defined on the same experiment, such as the features of one input.

covariance matrixkovaryans matrisi

The matrix of all pairwise covariances of a random vector; symmetric and positive semidefinite.

positive semidefinitepozitif yarı tanımlı

A symmetric matrix M with $a^\top M a \ge 0$ for every vector $a$; for a covariance matrix, no weighted sum has negative variance.

multivariate Gaussiançok değişkenli normal dağılım

The distribution of a Gaussian random vector, fixed completely by its mean vector and covariance matrix.

law of large numbersbüyük sayılar yasası

The average of i.i.d. variables with a finite mean converges to that mean as the number of variables grows.

central limit theoremmerkezi limit teoremi

The standardised average of i.i.d. variables with finite variance approaches a standard normal distribution.

HoeffdingHoeffding eşitsizliği

Hoeffding's inequality: a bound, valid at every n, on the chance that an average of independent variables in [0, 1] misses its mean by ε or more.

concentration inequality

Any bound on the chance that a random quantity, such as an average, falls far from its mean.

gambler's fallacykumarbaz yanılgısı

The false belief that after a streak, independent trials favour the outcome that has not appeared.

What comes next
§02 · Bayesian and frequentist machine learning

Next week the unknown becomes a parameter, such as a click rate, instead of an event. Bayes' rule and the beta family from this section come back with a job: turning data into a belief about that parameter, set against the frequentist answer to the same question.

Sources
  • textbookT. Hastie, R. Tibshirani, J. Friedman, The Elements of Statistical Learning, Springer, 2003 The textbook named in the syllabus. No section numbers are quoted in these notes, because this week's syllabus line gives none.
  • course materialEEE 485/585 chapter 1 lecture slides and lecture notes, Fall 2026 The order of topics and the notation follow them: Ω, F and P for the probability space, ω for the noise in Y = f(X) + ω, and Hoeffding's inequality for variables in [0, 1]. All wording, examples and exercises here are original.
  • course materialEEE 485 syllabus page on STARS, printed 21 September 2026 Source of the weekly line, the assessment weights quoted in the card and the requirements to sit the final exam.
  • textbookOther books the syllabus recommends: G. James et al., An Introduction to Statistical Learning (2013); K. P. Murphy, Machine Learning: A Probabilistic Perspective (2012); C. M. Bishop, Pattern Recognition and Machine Learning (2011) Listed as recommended, not required.
  • standard resultStandard normal tail values P(|Z| ≥ 1) = 0.317, P(|Z| ≥ 1.96) = 0.050 and P(|Z| ≥ 2) = 0.0455, used in the central limit theorem examples.

Spotted something missing or wrong? tell us · share your own notes or an old exam.

Last updated .