Kinds of learning
Last updated
“Learning from examples” covers several quite different setups, and the first question about any problem is which one it is. Do you have the right answers to learn from? Are they categories or numbers? Or are there no answers at all? This lesson sorts machine learning into four kinds, with a penguin example of each you can run, and then you sort twelve real tasks yourself.
By the end of this lesson you can
- Tell supervised, unsupervised, self-supervised and reinforcement learning apart
- Say whether a supervised task is classification or regression
- Explain how self-supervised learning makes labels out of the data itself
Supervised: learning from labels
In supervised learning, every training example comes with the right answer, its label. The model learns to go from an example's features to its label, so it can supply the label for new examples where nobody knows it yet. The spam filter in lesson 2.1 was supervised: every message was marked spam or ok.
The penguins are supervised data too: each one's measurements come with its species, written down by the scientists who measured it. This is the kind of learning Stages 2 to 4 are mostly about.
Classification and regression
Supervised tasks come in two kinds, depending on the label:
- Classification: the label is one of a few categories. Species, spam or ok, which digit is in a picture.
- Regression: the label is a number on a scale. Body mass, a house's price, tomorrow's temperature.
The same penguins give both:
Predicting species from measurements is classification. Predicting body mass from the other three measurements would be regression. The difference matters because it changes what a model outputs (a category, or probabilities for each; or a number), and how you measure its mistakes (lessons 2.7, 2.8 and 2.11).
Two questions settle which it is. Is an answer that's a little off still partly right? Predicting 4,100 g for a 4,200 g penguin is close; predicting Chinstrap for a Gentoo isn't "close" to anything. Does the average of two answers mean something? The average of two masses is a mass; the average of Adelie and Gentoo is nothing. Yes to both: regression. No: classification.
Some tasks could be framed either way, and the choice is yours. A star rating from 1 to 5 can be five classes or one number; "will it rain?" is a class, "how many millimetres?" a number. Choose the one that matches the decision someone will make with the answer.
Unsupervised: finding structure
In unsupervised learning there are no labels at all. The model looks for structure in the features alone: groups that belong together (clustering), the few directions the data mostly varies in (dimensionality reduction), or examples unlike the rest (anomaly detection).
Here, KMeans (lesson 4.8) is asked to split the penguins into 3 groups. It never sees the species. Afterwards, the table counts each group's real species:
Without being told, it put 123 Gentoos together with nothing else, and 127 Adelies with only 5 Chinstraps. The third group mixes 63 Chinstraps with 24 Adelies. The measurements alone almost tell the species apart, which is good news for lesson 2.4's classifier. But an unsupervised model can't tell you what its groups mean: group 1 is "Gentoo" only because we had the labels to check.
Self-supervised: labels from the data itself
Labels are expensive: someone has to write them. Self-supervised learning gets them free, by hiding part of each example and asking the model to predict it from the rest. The labels are cut out of the data itself.
The best-known case is predicting the next word. Every sentence ever written becomes many training examples:
Five examples from one six-word sentence, and no person labelled anything. Large language models (Stage 13) learn this way from huge amounts of text. Image models do the same by hiding patches of photos and filling them in. Mechanically it's supervised learning; what's different is where the labels came from.
Reinforcement: learning from rewards
In reinforcement learning, nobody gives right answers. A program (the agent) takes actions in some world, gets a reward now and then, and learns which actions lead to more reward over time. A game's score, a robot arm's "the block stayed put", a person clicking thumbs up.
Two things make it hard. The reward often comes long after the actions that earned it (which move won the game?). And the agent's own actions decide what it gets to learn from, so it has to balance trying new things against doing what already works. Stage 15 is about this kind of learning.
Other shapes of task
The four kinds cover most of machine learning, but within them, tasks come in a few more shapes you'll meet in this course and outside it:
- Multi-label classification: each example can have several labels at once. A photo can show a jeepney and a dog and rain. It's one yes-or-no question per label, rather than one choice among them.
- Ranking and recommendation: put things in order for someone. Search results, a shop's "you may also like", the next video. What matters is the order at the top of the list, not a score for each item.
- Forecasting: predict the future of a series over time, such as tomorrow's electricity demand or next month's rice price. It's regression, but the order of the rows matters: you may only learn from the past, never the future (lesson 2.10's leakage through time).
- Anomaly detection: flag the unusual, such as a faulty sensor reading or a strange card payment, often with no labels for what unusual looks like (lesson 4.12).
- Generation: make new text, images or sound. Large language models do this, trained self-supervised (Stages 13 and 14).
Naming the shape tells you which models, metrics and splits fit. A recommender scored by accuracy, or a forecast tested on a shuffled split, measures the wrong thing.
Sort twelve tasks
Which kind of learning is each task? Some fit more than one.
0 of 12 placed right
Tell from a photo whether a mango is ripe, after learning from photos farmers have labelled
Predict tomorrow’s electricity use in Metro Manila from past days’ use and weather
Split a shop’s customers into groups that buy alike, with no groups given in advance
Train a language model to guess the next word, on billions of sentences from the web
Teach a robot arm to stack blocks by giving it a point each time a block stays put
Estimate a house’s price from its size, rooms and location, using past sales
Flag card payments unlike any the cardholder has made before, with no fraud labels
Learn to play a video game well from the score alone
Sort support emails into “billing”, “delivery” or “other”, from emails staff already sorted
Hide patches of photos and train a model to fill them in, to learn what pictures look like
Squash 50 measurements of each patient down to two numbers you can plot
Tune a chatbot’s answers using people’s thumbs up and thumbs down
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Goodfellow, Bengio and Courville, Deep Learning, chapter 5: Machine Learning Basics: tasks such as classification and regression, and supervised and unsupervised learning (5.1)
- Prince, Understanding Deep Learning: chapter 1: supervised, unsupervised and reinforcement learning
- scikit-learn: Clustering, k-means: the KMeans model used in step 3