Supervised vs unsupervised learning
Learning from examples that come with the right answer, versus finding structure in data that has no answers at all.

In this lesson you will
- Define supervised learning as learning a mapping from inputs x to known outputs y
- Tell regression (predict a number) from classification (predict a category)
- Describe unsupervised learning and clustering, and recognise when to use it
Last lesson you saw that machine learning means learning from examples. But examples come in two very different flavours: some come with the right answer attached, and some don’t. That single difference splits machine learning into its two biggest families.
Supervised learning: learning from right answers
In supervised learning, every example comes with the answer we want the computer to learn. We call the input and the answer, or label, :
| Input | Output | Application |
|---|---|---|
| an email | spam or not spam | spam filter |
| a photo of a skin spot | harmless or worth checking | medical screening |
| a sentence in English | the same sentence in French | translation |
| a house’s size | its sale price | price estimate |
The model sees many pairs, learns the mapping from to , and can then predict for an it has never seen. It’s called supervised because the labels act like a teacher checking every answer.
Supervised problems come in two main kinds:
- Regression predicts a number from a continuous range: a price, a temperature, minutes until your bus arrives. There are infinitely many possible answers.
- Classification predicts a category from a small set: spam or not spam, cat or dog or rabbit, which digit was handwritten. The answers are a short list.
The rest of this section is about regression. Classification comes in Section 3.
Unsupervised learning: finding structure without answers
Now imagine you run a shop and have data on hundreds of customers (how often they visit, how much they spend) but nobody has labelled them. There is no “right answer” column. You can still ask a useful question: are there natural groups in here?
That is unsupervised learning: the data has only inputs , no labels , and the algorithm’s job is to find structure on its own. The most common kind is clustering, grouping similar points together. Others include anomaly detection (spotting the odd one out, like an unusual card payment) and dimensionality reduction (squeezing big data into fewer numbers while keeping what matters).
See the difference
Below is the customer data. Toggle Show labels to switch between a supervised view (each customer’s group is known, shown by colour) and an unsupervised one (just grey dots). Then let the k-means algorithm find the groups by itself: it drops markers, called centroids, assigns every point to its nearest centroid, moves each centroid to the middle of its points, and repeats until nothing changes.
Each dot is a customer: how often they visit, and how much they spend. The colours are labels someone gave us, so this is the supervised view.
Things to try:
- Set to 2 or 5. The algorithm always finds exactly groups, even when that’s not the “true” number, so choosing is part of the job.
- Press New random start a few times with . Usually it finds the three groups, but a bad start can get stuck in a worse answer (a local minimum). Real systems run k-means several times and keep the best result.
Check yourself
Self-check · 4 questions