Machine Learning · Topic 1 · Introduction to Machine Learning · Interactive sheet · Intermediate

TheIntroduction to Machine Learning Blueprint

Machine learning lets a computer write its own rule from examples instead of a person writing it by hand: give it data with the right answers, data alone, or a reward, and it finds the pattern. How well that works depends on the features you measure, and on whether you have enough examples once the number of features grows.

Every number on this page is clickable. Every underlined term has a definition.

Before you startWhat a mean and a standard deviation are, how to read a scatter plot with two axes, and Pythagoras’ theorem for the distance between two points. Fitting a straight line, as in Linear Regression, helps but is not required.

1959
“machine learning” named
E · T · P
the defining rule
784
features per digit
10ᵈ
samples for 10 per axis
79 %
of each axis for 10 % of data, 10-D
01

Rules nobody can write by hand

Telling spam from real mail has no complete rule a programmer can write down. Machine learning turns the problem around: show the computer labelled examples and let it find the rule. Tick your own rules below, then let the computer learn one.

Filter 14 emails: your rules vs a learned rule

1959
Samuel’s checkers player
1997
Mitchell’s definition
70,000
labelled digits in MNIST
4–1
AlphaGo vs Lee Sedol, 2016

The headline: the program is an output

Traditional programming: data + rules → answers.

Machine learning: data + answers → rules. The learned rule, the model, then answers new cases. Whether it is any good is measured only on cases it has not seen.

1936Iris data 1957curse named 1959“machine learning” 1997E · T · P 2012deep learning wins 2016AlphaGo
02

Walk one problem from question to answer

Thirty iris flowers, two features each (petal length and width). Follow them stage by stage through a supervised pipeline, or switch to the unsupervised and reinforcement versions. Drag, click a bead or press play.
setosa versicolor virginica
Supervised · Iris species100%
stage scrubber1
stage

Quick check
Why are the 6 test flowers kept out of training, and out of the mean and standard deviation used for scaling?
The test set stands in for future flowers. If any of its information leaks into training, even through the scaling statistics, the measured accuracy is too optimistic.
03

Three ways a machine can learn

What the learner is given decides the kind of learning: the right answers (supervised), nothing but the data (unsupervised), or a reward after acting (reinforcement). Play with one small demo of each.

Idea 1 · supervisedFit the examples, but not too well

model flexibility: polynomial degree3
training error
test error

Idea 2 · unsupervisedFind groups nobody labelled

number of clusters k3

Idea 3 · reinforcementLearn from reward by trying

exploration ε (share of random tries)0.10
reward / pull
0
best arm chosen
0 %
Quick check
As you raise the degree, the training error keeps falling but the test error starts to rise. What is happening?
A very flexible curve bends to every random wiggle of the training points. Those wiggles do not repeat in new data, so the test error grows: overfitting.
04

The defining rule: more experience, better performance

Mitchell’s definition: a program learns from experience E at task T, measured by P, if P improves with E. Here a programmer’s fixed rule competes with a nearest-centroid learner as the number of labelled examples grows. Move the sliders.
test accuracy P vs number of training examples E (log scale)100%
hand rule: ŷ = B if x₁ > 0.5 · learned: μ_c = (1/n_c) Σ xᵢ, ŷ = argmin_c ‖x − μ_c‖ · P = correct ÷ 2,000
experience E: labelled examples8
class overlap σ (noise)0.12
hand rule
vs
learned
dashed: hand rule · shading: learned rule · one training set of size E

T, P, E for this lab. Task T: sort points into class A or B. Performance P: accuracy on 2,000 new points. Experience E: the labelled examples. The learner improves with E and levels off near the best possible accuracy, which overlap σ sets.

Quick check
For a spam filter, which of these is the experience E in Mitchell’s definition?
E is the data the program learns from: labelled emails. T is the sorting task, and P is the share sorted correctly. A banned-word list is a hand-written rule, not experience.
05

Distance between feature vectors, by hand and by eye

Once each example is a feature vector, “similar” means “close”. The k-nearest-neighbour rule predicts the majority label among the k closest training examples, using the Euclidean distance. Do it on paper first, then with real Iris rows.

Worked example by hand: one query, four labelled points

Query q = (2, 3). Two features, so each distance is Pythagoras: subtract, square, add, take the square root. Then sort and let the k nearest vote. Do each line on paper before you press Next.

d(q, p) = √( (q₁ − p₁)² + (q₂ − p₂)² ) · ŷ = majority label of the k smallest d
neighbours k3
units of petal length
prediction
nine rows of Fisher’s Iris data · query in red · lines to the k nearest100%
Quick check
A query is at (0, 0). Its neighbours are ▲ at (3, 4), ● at (1, 1) and ▲ at (0, 2). What does 3-NN predict, and what is the largest of the three distances?
Distances: √(9 + 16) = 5, √(1 + 1) ≈ 1.41, √(0 + 4) = 2. With k = 3 all three vote: ▲ twice, ● once, so ▲. Adding the coordinates (3 + 4 = 7) is not a distance.
06

Where the test error comes from

Expected test error splits exactly into three parts: bias² (too simple), variance (too jumpy) and irreducible noise. The bars are computed live by fitting each polynomial to 100 random training sets from y = sin(2πx) + noise. Click a bar for its arithmetic.
100%
noise σ²bias²variance
click a bar

The arithmetic for that model appears here.

Best trade-off

The identity

E[(y − ŷ)²] = bias² + variance + σ²

Each bar’s total is the sum of its three parts; the shares are part ÷ total.

Quick check
Switch from 20 to 80 training points. Which part of the error shrinks most for the flexible degree-9 model?
More data pins a flexible model down, so it changes less from sample to sample: variance falls. Bias depends on how flexible the model is, and the noise is a property of the data, so neither moves much.
07

The family of learning settings

Six settings, told apart by one question: what feedback does the learner get? Click a column to compare; the three main ones can be loaded into the walker of section 02. Transfer learning sits across all of them.
comparator · click a row100%
setting

Pick a column above.

Labels are the expensive part. Measuring a flower takes seconds; deciding its species takes a botanist. Settings that need fewer labels (unsupervised, semi-supervised, self-supervised, transfer) exist because labels cost time and money.

Quick check
A robot learns to walk by trial and error and is scored by the distance it covers before falling. Which setting is this?
Nobody tells the robot the correct joint angles (no labels). It acts, the world responds, and a reward signal (distance) scores the result: reinforcement learning.
08

The limit: the curse of dimensionality

Each extra feature adds an axis. Space grows exponentially with the number of axes, so data that looked dense becomes sparse and “nearest” neighbours stop being near. Slide the dimension d and watch the four estimates of the curse.
dimensions d (number of features)10
samples per axis you want10
share of data a neighbourhood should hold10 %
random points N (for the distance test)500
samples for the same density
edge of a cube holding that share
cube volume inside its inner ball
distance contrast (far − near) ÷ near
distance contrast vs d (log–log, N random points)100%
Quick check
You want 10 samples along every axis. How many samples does that take with 3 features, and with 6?
kᵈ: 10³ = 1,000 and 10⁶ = 1,000,000. Doubling the number of features squared the data you need; it did not double it.
09

Apply it to a new problem

Seven steps take you from a vague question to a measured model. Answer three questions on the right to choose the learning setting, and the scikit-learn starter code follows your answers.
Frame it: write down T, P and E
T = what decision? · P = which number decides “good enough”? · E = which examples exist?
Pick the setting from the feedback you have
labels → supervised · none → unsupervised · reward → reinforcement
Choose and build features
measurable, available at prediction time, few and informative (section 08)
Split before you look: train / validation / test
e.g. 60 / 20 / 20 %; the test set is touched once, at the end
Start with a baseline
majority class, or a simple model such as k-NN; any later model must beat it
Fit on train, tune hyperparameters on validation
k for k-NN, degree for a polynomial: pick the value with the lowest validation error
Report P on the test set and check failures
accuracy plus a confusion matrix; look at the examples it gets wrong

Which setting?

Do the examples have answers?
Does the system act and get a score?
How many labelled examples?

      
Quick check
You try k = 1, 3, 5, … 15 for k-NN. Which data should decide the best k?
On the training set k = 1 always wins (each point is its own nearest neighbour). Choosing on the test set uses it up, so its score is no longer an honest estimate. The validation set exists for this choice.
10

From 150 flowers to billions of examples

Experience E is what learning feeds on. The landmark datasets grew by more than seven orders of magnitude, from Fisher’s 150 flowers to billions of web images. Click a point for its story; the red line marks 1959, when the field was named.
size of landmark datasets (examples, log scale)100%
click a point

Before machine learning → with machine learning · tap a card to flip

Quick check
Most core ideas (nearest neighbours, the perceptron, reinforcement learning) existed by 1990. Why did machine learning take off mainly after 2009?
By Mitchell’s definition, performance grows with experience. Datasets like ImageNet, together with GPUs to process them, gave the old ideas enough E to beat hand-written rules.
11

Where machine learning is used today

Every setting on this page runs in products you use daily. Click each row to see which setting, which features, and what came next.
Each email or card payment becomes a feature vector (words, links, sender, amount, place, time). A classifier trained on millions of labelled cases scores new ones in milliseconds. Fraud is rare, so accuracy alone misleads: a filter that never flags anything is 99.9 % “accurate”. Precision and recall are reported instead.
Clustering purchase histories finds groups such as “weekend bulk buyers” without anyone defining them first. Points far from every cluster are flagged as anomalies: a strange login, a failing machine sensor.
Streaming and shopping sites learn a short feature vector for every user and every item from past clicks and ratings, so that close vectors mean “likely to enjoy”. This reduces millions of items to a few dozen learned dimensions, a direct answer to the curse of dimensionality.
Hospitals rarely have millions of labelled scans. A network pretrained on general photos is reused and fine-tuned on a few thousand labelled X-rays or skin images. The learned low-level features (edges, textures) transfer; only the top layers are retrained.
TD-Gammon (1992) learned backgammon by self-play; AlphaGo beat Lee Sedol 4–1 in 2016. Reinforcement learning also tunes robot controllers and industrial control loops, where the reward is distance walked or energy saved.
Large language and image models learn first from unlabelled text and pictures by predicting hidden parts (self-supervised), are then fine-tuned with labelled examples (supervised, transfer), and are often polished with human preference scores (reinforcement learning from human feedback). All the settings of section 07 in one system.
Quick check
A hospital has 2,000 labelled chest X-rays and wants a classifier. Which approach does this section suggest?
2,000 labels are too few to train a large network from scratch without overfitting. Reusing a pretrained network’s features and fine-tuning the top is transfer learning.
12

Key takeaways

Eight sentences to remember. Click each for the evidence on this page.
The learned spam rule in section 01 beat every combination of hand-ticked rules. The term goes back to Samuel (1959).
Mitchell (1997). In section 04 the hand rule stays flat while the learned rule climbs with every doubling of the examples.
Three demos in section 03, three pipelines in the walker of section 02, six settings side by side in section 07.
Use it when you have few labels but a related pretrained model exists (sections 07, 09 and 11).
Similar examples are close points. k-NN uses d = √Σ(qᵢ − pᵢ)², and units matter: standardise first (section 05).
Training error falls as the model grows more flexible, test error turns up again: overfitting (section 03). Split before scaling to avoid leakage (section 09).
Simple models have high bias, flexible models high variance; more data lowers the variance (section 06).
10 samples per axis in 10-D is 10¹⁰ samples; capturing 10 % of the data takes 79 % of every axis; distances lose their contrast (section 08).
13

Check your understanding

Five questions, instant feedback, every answer explained. Score 4 or more and the stamp is yours. Click a dot to jump to a question.
0 / 5
answer all five
■ STAMPED · ML BLUEPRINT · APPROVED
14

Glossary

Every term used on this page. Type to filter; click a term to open its definition.