Privacy note: We capture your IP address to provide customised and focused services. See our Privacy Policy.

Machine Learning Foundations — Alpha School

Lesson 4: Types of Learning: Supervised, Unsupervised and Reinforcement

Machine learning comes in three main flavours, and the difference between them is what kind of feedback the learner gets. In supervised learning, every example comes with the right answer attached, and the model learns by checking its guesses against those answers. In unsupervised learning, there are no answers at all — the model must find structure in the data by itself. In reinforcement learning, there are no right answers either, but the model gets rewards and penalties for its actions, and learns by trial and error. Most real systems use one of these three, or a mix of them.

Supervised learning is the most common kind, and you have already met it twice: the house-price model, which predicts a number, and the spam filter, which predicts a category. When the answer to predict is a number — a price, a temperature, a test score — the task is called regression. When the answer is a category — spam or not spam, a digit from 0 to 9, a disease present or absent — the task is called classification. In both cases the recipe is the same: labelled examples in, a trained model out, and a test set to check whether it generalises.

Finding structure without answers

Unsupervised learning is for questions where nobody knows the answer in advance. A shop might ask: do our customers fall into natural groups, such as bargain hunters, regulars and big spenders? Nobody has labelled the customers, so the model groups them by similarity instead, putting customers who buy similar things together. That is clustering, which you will study in Lesson 13. Another unsupervised task is dimensionality reduction: squeezing data with hundreds of measurements down to a few that still capture what matters, which makes it easier to draw, explore and feed into other models.

Reinforcement learning works more like training a dog than like studying a textbook. An agent takes actions in an environment — a game, a robot, a simulated warehouse — and receives a reward when it does well and a penalty when it does badly. There is no teacher showing the right move; the agent discovers good behaviour by trying things and remembering what paid off. This is how programs learned to play board games and video games at a very high level, and how robots learn to walk or grasp objects. It is powerful, but it needs a safe place to practise, because learning by trial and error in the real world can be slow, expensive or dangerous.

Choosing the right kind of learning

A fourth flavour: learning from a little labelling

In practice, labels are expensive and unlabelled data is cheap, so a fourth pattern is common: semi-supervised learning. Imagine a worked example: a hospital has a thousand scan images labelled by doctors, and a hundred thousand unlabelled ones. Labelling them all would take years, but the unlabelled images still carry useful information about what scans typically look like. A semi-supervised method first learns the general structure of all the images — which shapes and textures occur together — and then uses the thousand labelled examples to attach meanings to that structure. The result is often nearly as good as labelling everything, at a fraction of the cost. You will meet the same idea again in language models, where enormous amounts of unlabelled text teach a model the patterns of language before a small amount of labelled data teaches it a particular job.

The first question in any machine learning project is therefore not which algorithm to use, but which kind of learning fits the problem. Do you have labelled examples and a clear answer to predict? That is supervised learning. Do you have data but no labels, and want to discover groups or patterns? That is unsupervised learning. Do you have an environment where an agent can try actions and get rewards? That is reinforcement learning. Getting this choice right matters more than any later detail, because the wrong kind of learning cannot be rescued by a clever algorithm. In the next unit you will build the two most important supervised models, step by step.

Watch & Learn

One video to watch for this unit, from a trusted educator.

  • Machine Learning for Everybody – Full Course — freeCodeCamp
    Kylie Ying's beginner-friendly full course covers the ideas of this unit — data, features, classification and regression — with worked examples you can follow along with.

Key Terms

Supervised learning
Learning from labelled examples, where the model checks its guesses against the right answers.
Unsupervised learning
Learning from data with no labels, by finding structure such as groups or patterns.
Reinforcement learning
Learning by trial and error: an agent takes actions and learns from the rewards and penalties it receives.
Regression
A supervised task where the answer to predict is a number, such as a price.
Classification
A supervised task where the answer to predict is a category, such as spam or not spam.
Clustering
An unsupervised task that groups similar examples together without any labels.
Agent
In reinforcement learning, the learner that takes actions in an environment.
Reward
A signal, such as points in a game, that tells a reinforcement learning agent an action was good.

Discussion Questions

  1. A hospital wants to predict which patients are at risk of a disease. Which kind of learning fits, and what would the labels be?
  2. A music app wants to group its listeners into taste groups, but nobody has labelled them. Which kind of learning fits, and what would the groups be used for?
  3. Why is reinforcement learning a poor choice for teaching a self-driving car entirely on real roads?

Practice Questions

  1. What is the key difference between supervised and unsupervised learning?
  2. Is predicting a house price regression or classification? Why?
  3. Give one example of a clustering task.
  4. How does a reinforcement learning agent learn without a teacher?
  5. You have photos of animals but no labels, and you want to find natural groups among them. Which kind of learning?
Show answers
  1. Supervised learning uses labelled examples; unsupervised learning has no labels. In supervised learning the model checks guesses against right answers; in unsupervised learning it must find structure on its own.
  2. Regression, because the answer is a number. Regression predicts continuous numbers; classification predicts categories.
  3. Grouping shop customers into bargain hunters, regulars and big spenders. Clustering finds natural groups by similarity, with no labels to guide it.
  4. By trying actions and learning from the rewards and penalties it receives. Good actions earn rewards, so the agent gradually repeats the behaviour that pays off.
  5. Unsupervised learning, specifically clustering. There are no labels, so the model must group the photos by similarity itself.
Keep reading to complete this lesson