The same data can feed two completely different kinds of learning. Knowing which you are doing — and what "learning" even means — is the foundation under every method that follows.
Every dataset you analyse has the same shape: a table. Each row is one observation (a customer, an employee, a store). Each column is a feature (also called a variable or predictor) — something you measured. In supervised learning, one special column is the target (or label, or outcome): the thing you want to explain or predict.
X = the features (inputs) → y = the target (output)
Xthe matrix of everything you know about each row (age, tenure, spend…).
ythe single column you are trying to explain or predict. If there is no y, the problem is unsupervised.
Below is a raw customer table. Click a column header to nominate it as the target (y). Everything else becomes the features (X). The point: you decide what the target is — and that decision defines the whole study.
Interactive 1 of 3 — click a column header to make it the target.
Click a header above…
2 · WHAT "LEARNING" ACTUALLY MEANS
THE CORE MECHANISM
Learning = minimising a loss
This is the idea that unifies almost all of machine learning, and you already met it in Part 1. A model makes predictions; we measure how wrong it is with a loss function; then we adjust the model to make that loss smaller. "Training" is just this loop, repeated:
guess → measure loss → adjust → repeat
lossa single number summarising total error. For a continuous target it is usually the squared error from Part 1: Σ(yᵢ − ŷᵢ)². Lower loss = better fit.
Supervised learning has a target, so it can compute loss — it always knows the "right answer" for the training rows. Unsupervised learning has no target, so there is no right answer to score against; instead it optimises a different objective, like making groups tight. Watch this loop run live: the model starts as a bad random line and descends toward the least-squares fit, one step at a time.
Interactive 2 of 3 — press Step (or Run) and watch the loss fall as the line learns.
Iteration
0
Loss (SSE)
—
Slope b₁
—
This is gradient descent. Each step nudges the slope in the direction that lowers the loss most steeply. Neural networks, logistic regression, and boosting all use versions of this exact loop — just with more parameters. You have now seen the heart of "machine learning."
3 · THE TWO FAMILIES
PRACTICE
Sort real problems into the right family
One question decides it every time: "Is there a known outcome column I'm trying to reproduce?" Yes → supervised. No, I'm looking for hidden structure → unsupervised.
Interactive 3 of 3a — tap a case, then the correct family.
Tap a case, then a bin.
SUPERVISED — has a target y
UNSUPERVISED — no target, find groups
0 / 6 sorted
UNSUPERVISED, MADE CONCRETE
How k-means finds groups with no labels
The most common unsupervised method is k-means clustering. With no target to aim at, it optimises a different objective: make each group as tight as possible. The algorithm is almost embarrassingly simple, and it is worth knowing the four steps because examiners ask:
Choose k (how many groups you want). You pick this — it is a judgement, not an output.
Drop k "centres" at random.
Assign each point to its nearest centre (distance = the objective).
Move each centre to the average of its assigned points. Repeat 3–4 until nothing moves.
Press the buttons to run those exact steps on real-looking data. Notice the centres drift into the heart of each cloud, and the total within-group distance (the objective, sometimes called inertia) drops.
Interactive 3 of 3b — set k, then alternate Assign and Move.
Step
place centres
Inertia (tightness)
—
The honest caveat. k-means always returns groups — even in random noise. And different random starts can give different groupings. So in a thesis, clusters are a hypothesis to interpret and validate, never a proven fact. "The algorithm found 3 segments" is not a finding; "these 3 segments differ meaningfully on X and Y, and replicate across starts" is.
Scroll progress saves on this device. Part of the DBA Data-Analysis series by Jan Erik Meidell.