Supervised, Unsupervised and Reinforcement Learning
Machine learning means a computer program finds its own rule from data instead of a person writing every rule. But not all learning looks the same. There are three main ways a machine can learn, and each one fits a different kind of problem. This guide explains all three with an example you could act out in a classroom.
1. Supervised learning: learning from labeled examples
In supervised learning, every example comes with the right answer attached. That answer is called the label. It is "supervised" because it is a bit like learning with a teacher who has marked every practice question.
A spam filter is a good example. People mark lots of emails as "spam" (junk) or "not spam". The program looks at those labeled emails and finds patterns, such as certain words or strange links, that tend to appear in spam. Then, when a new email arrives with no label, it uses those patterns to guess.
Supervised learning comes in two flavors:
- Classification: the answer is a category, such as spam or not spam, cat or dog, or which digit from 0 to 9 is in a picture.
- Regression: the answer is a number, such as how many minutes a bus journey will take or how tall a plant will grow.
Classroom example: the leaf sorter
Collect 20 leaves from two kinds of tree. For each leaf, measure its length and width and write down the tree it came from. That tree name is the label. Now hide 5 leaves and use the other 15 to come up with a rule, for example "leaves wider than 6 cm come from tree A". Test your rule on the 5 hidden leaves. How many did it get right?
You just did supervised learning by hand: you learned a rule from labeled examples and tested it on examples you had not used. The guide to data and datasets shows how to set up a table like this carefully.
2. Unsupervised learning: finding groups with no labels
In unsupervised learning, the examples have no labels at all. Nobody says what the right answer is. Instead, the program looks for structure: which examples are similar to each other, and which are different.
The most common job is clustering: putting examples into groups (called clusters) so that things in the same group are alike. A music app might group songs that sound similar without anyone naming the groups first. A shop might group customers who buy similar things.
The program can find the groups, but it cannot tell you what they mean. People have to look at each group and decide whether it makes sense.
Classroom example: the button sort
Tip a box of mixed buttons onto a table. Do not give any names or categories. Ask pupils to sort them into groups of buttons that seem to belong together. Different groups of pupils may sort by size, by color or by number of holes, and all of those can be sensible.
That is unsupervised learning: finding groups by similarity, with no right answer given in advance. Discuss: which sort was most useful, and useful for what?
3. Reinforcement learning: trial, error and reward
In reinforcement learning, there is no table of examples. Instead, a program called an agent takes actions in some kind of world, such as a game, and after each action it gets a reward (points) or no reward. Over many tries it learns which actions tend to earn the most reward in the long run.
Learning to play a game is the classic example. At first the agent presses buttons almost at random. Moves that lead to points become more likely; moves that lead to losing become less likely. After a great many games it can play well, even though nobody told it the rules of good play.
Reinforcement learning usually needs a huge number of tries, which is why it is often done in games and computer simulations where trying is fast and nothing real can break.
Classroom example: hot and cold
One pupil is the agent and waits outside while the class hides an object. When the agent comes back, they may only take one step at a time. After each step the class says "warmer" (a reward) or "colder" (no reward). Nobody tells the agent where the object is. The agent learns from the rewards which way to go.
Discuss: what happens if the class gives the rewards wrongly? (The agent learns the wrong path. A reward that measures the wrong thing teaches the wrong thing.)
The three side by side
| Type | What the data looks like | What it learns | Everyday example | Classroom example |
|---|---|---|---|---|
| Supervised | Examples with labels (the right answers) | A rule from features to labels | Spam filter | The leaf sorter |
| Unsupervised | Examples with no labels | Groups or patterns of similarity | Grouping similar songs | The button sort |
| Reinforcement | Actions and rewards, no table | Which actions earn the most reward | Learning a game | Hot and cold |
There are also mixtures, such as learning from a few labeled examples and many unlabeled ones, but these three are the main ideas to know first.
Why labels decide which kind you can use
Here is a mistake that is easy to make. Suppose you want to sort photos of animals into "cat" and "dog", but your photos have no labels. You might think that is a classification problem. But classification is supervised: to learn "cat" and "dog", the program needs examples that say which is which.
Without labels, all a program can do is group the photos by similarity and hope the groups turn out to be cats and dogs. They might instead turn out to be "photos taken indoors" and "photos taken outside". You would have to look and check.
The ML Algorithm Selector on this site follows exactly this logic. If you choose "classification" but answer "no" to "is your data labeled?", it suggests clustering methods (K-Means, DBSCAN and Hierarchical Clustering), because without labels you cannot train a classifier. With labels, it suggests classifiers instead. Like every result it gives, these are starting points: always train a few and compare them on your own data. The guide to choosing a machine learning algorithm walks through all of its questions.
Questions to talk about
- A program learns to recommend books from what people borrowed. Which kind of learning is closest, and why might it be a mixture?
- You want to guess how many people will come to the school fair. Is that classification or regression?
- In hot and cold, what would happen if "warmer" were only said for big steps? What would the agent learn?
If you would like more hands-on versions of these, the unplugged machine learning activities need only paper, cards and a group of people.