Supervised vs unsupervised learning

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

Lesson · 12 min

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 xx and the answer, or label, yy:

Input xxOutput yyApplication
an emailspam or not spamspam filter
a photo of a skin spotharmless or worth checkingmedical screening
a sentence in Englishthe same sentence in Frenchtranslation
a house’s sizeits sale priceprice estimate

The model sees many (x,y)(x, y) pairs, learns the mapping from xx to yy, and can then predict yy for an xx 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 xx, no labels yy, 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 kk markers, called centroids, assigns every point to its nearest centroid, moves each centroid to the middle of its points, and repeats until nothing changes.

Loading the interactive graphic…

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 kk to 2 or 5. The algorithm always finds exactly kk groups, even when that’s not the “true” number, so choosing kk is part of the job.
  • Press New random start a few times with k=3k = 3. 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

Supervised vs unsupervised learning

1. What makes a learning problem supervised?
2. Predicting tomorrow's maximum temperature in degrees is an example of…
3. A music service groups millions of songs into styles without anyone labelling them. Which kind of learning is this?
4. In the k-means widget, what happens in each round after points are assigned to their nearest centroid?