TL;DR
Supervised learning is learning from examples where the correct answer is already known. You give the model many pairs of an input and its label, such as a photo and the word "cat", and it adjusts its settings so that its predictions match those labels. The point is not to repeat the training answers but to get new inputs right.
It is the most common form of machine learning in practice, because many useful problems come with a history of labelled examples.
Where you'll see it: in spam filters trained on emails marked spam or not spam, in price models trained on past house sales, and in the stage of language model training that teaches the model to answer questions the way a labeller would.
Intuition
Learning with the answers shown
A child learning to name fruit is shown an apple and told "apple", then a banana and told "banana", and so on. After enough examples the child names a fruit they have never seen. The answer given with each example is the label. That is what makes the learning supervised: someone supplies the right answer, and the learner's job is to match it.
In machine learning the data is a list of pairs , where is an input and is its label. The model is a function with adjustable settings, called parameters and written . Training searches for settings where the model's prediction for is close to across all the pairs. "Close" is defined by a Loss Function, which turns each mistake into a number.
flowchart LR A["Labelled examples (x, y)"] --> B["Model predicts f(x)"] B --> C["Loss compares f(x) with y"] C --> D["Adjust the parameters"] D --> B E["New input"] --> F["Trained model"] F --> G["Predicted label"]
The goal is new data, not memory
Matching the training pairs is not enough. A lookup table that stores every training example would be perfect on the training set and useless on anything new. The real aim is to be right on new inputs drawn from the same kind of data as the training set. The gap between "right on the examples I saw" and "right on the examples I will see" is the central difficulty of the whole field. When a model learns the quirks of its training set instead of the general pattern, it is Overfitting.
The plot below shows the idea with a line. The dots are labelled training pairs, and the line is the least-squares fit to them, . It does not pass through every dot, and it should not: the dots carry noise, and the line is trying to capture the trend.
- learned model
- training pairs
The math
Setting up the problem
Given a training set of inputs from an input space and labels from a label space , supervised learning chooses a predictor from a family of predictors indexed by parameters , so that is a good guess for the label of a new input .
The input space is the set of things the model can see, such as all possible images of a fixed size. The label space is the set of answers it can give, such as the numbers from zero to one for a probability, or the list of animal names. The family of predictors is the set of shapes the model is allowed to take: straight lines, decision trees, or neural networks with a given architecture. Choosing picks one member of that family.
Empirical risk
Each candidate is scored by the average loss over the training set:
Here is the loss function, is the number of training pairs, and is called the empirical risk, because it is computed from the data we have. Training means finding
the settings with the smallest average loss. How to search for that minimum is the subject of Gradient Descent.
What we actually want
The quantity we care about is the expected loss on new data drawn from the same unknown distribution that produced the training pairs:
For any single fixed , the training average approaches as grows, by the Law of Large Numbers. The catch is that was chosen by looking at the training data. It was picked because it does well on those particular pairs, so tends to be lower than . Training error is an optimistic measure. The honest measure is performance on pairs the model has not been tuned on.
Regression and classification
The type of label decides the setup:
| Label type | Name | Typical loss | Example |
|---|---|---|---|
| real number | regression | Mean Squared Error | price of a house |
| one of a fixed set of categories | classification | Cross-Entropy Loss | spam or not spam |
Regression predicts a quantity. Classification predicts which bin an input falls into. The training procedure is the same in both cases: pick a loss, average it over the data, and minimise.
Training, validation and test sets
In practice the labelled data is split three ways. The training set is used to fit the parameters. The validation set is used to compare choices such as model size or learning rate. The test set is kept aside and used once, to report how the final model performs. The reason for the split is the optimism described above: any number computed on data that influenced the choices will overstate performance. See Train, Validation and Test Sets.
Worked examples
Training pairs: , , . The model is a line through the origin, , with one parameter . Use squared error as the loss. We want the that minimises the sum of squared errors .
- Take the derivative with respect to and set it to zero: .
- Rearrange: , so .
- Compute the sums: and .
- So .
- The predictions are , and . The errors are , and .
- The training mean squared error is .
Interpretation: the line fits the three points closely but not exactly. The residuals are small and do not all point the same way, which is what a good fit looks like. The number is the training error, and it says nothing yet about a fourth point we have not seen.
A team labels 1,000 emails as spam or not spam. They use 800 for training and keep 200 as a test set. They compare two models.
Model A reaches 99% accuracy on the training emails and 97% on the test emails.
Model B reaches 100% on the training emails and 81% on the test emails.
- Model B's training accuracy is correct out of 800.
- Model B's test accuracy is correct out of 200, so mistakes.
- Model A's test accuracy is correct, so mistakes.
- Model B looks perfect on the data it learned from, yet it makes more than six times as many mistakes as Model A on new email.
- The gap between training and test accuracy is the signal. Model B has memorised the training emails, including their quirks, and has not learned the general pattern of spam.
Interpretation: choose by test accuracy, not training accuracy. Here Model A is the better model even though its training number is lower.
Tradeoffs and failure modes
Supervised learning is the right tool when you have inputs, a clear target, and enough reliable labels. It is the wrong tool when labels do not exist, or when the goal is to discover structure with no particular answer in mind.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Few labelled examples | The model memorises noise, so it [[overfitting | overfits]] |
| Labels are expensive to get | Labelling becomes the bottleneck | Self-Supervised Learning or Transfer Learning from a model trained elsewhere |
| Labels are wrong or inconsistent | The model learns the mistakes | Clean the labels and measure how often annotators disagree |
| Test data differs from training data | Accuracy drops with no warning | Collect data closer to deployment and monitor it |
| Classes are very unbalanced | Accuracy looks high while the rare class is missed | Report Precision and Recall instead of accuracy |
Three failure modes deserve particular attention. The first is tuning on the test set: once the test set has shaped a decision, it is no longer an unbiased estimate. The second is leakage, where information that would not be available at prediction time, such as the outcome itself, sneaks into the inputs and makes the training score look excellent. The third is class imbalance: if 99% of parts are fine, a model that always says "fine" scores 99% accuracy and is useless.
History
The core idea of fitting a model to known answers is much older than computers. In the early 1800s, Adrien-Marie Legendre published the method of least squares in 1805 to fit the orbits of comets, and Carl Friedrich Gauss claimed to have used it earlier. Both were fitting a formula to measured observations, which played the role of the labels.
The machine version began in the late 1950s. Frank Rosenblatt's perceptron, around 1958, learned the weights of a simple classifier from labelled examples by nudging them after each mistake. It could not learn everything, and interest faded for a while. Backpropagation, popularised in 1986 by Rumelhart, Hinton and Williams, made it practical to train multi-layer networks with the same labelled-example recipe.
What made supervised learning dominant was data and compute. Large labelled datasets such as ImageNet, released in 2009, gave models enough examples to learn from. In 2012, a deep convolutional network trained on ImageNet by Krizhevsky, Sutskever and Hinton cut the error rate of image classification sharply, and the same recipe spread to speech, translation and many other tasks.
Check yourself
QuestionRecall: what is a label, and how does it differ from an input?Show answer
An input is what the model sees, such as a photo or a row of measurements. A label is the correct answer for that input, such as "cat" or a price, which is supplied with the training example. Supervised learning is defined by having labels for the training data.
QuestionComputation: using the fitted model from the tiny example, , what does it predict for ?Show answer
The prediction is . The point is outside the training inputs, so this number is an extrapolation and should be trusted less than a prediction inside the range of the data.
QuestionWhy: why is a low training loss not, on its own, evidence that a model will work on new data?Show answer
Training loss is measured on the same pairs the parameters were chosen to fit, so it is an optimistic estimate. A flexible model can drive the training loss close to zero by memorising the examples, including their noise, and still perform badly on new inputs. Only a held-out test set, one not used for any decision, gives an honest estimate of how the model generalises.
QuestionApplied: a factory's inspection model says every part is fine and scores 99% accuracy, because 99% of parts really are fine. What is the problem and what should the team measure?Show answer
The model has learned nothing useful: it ignores the input and always predicts the common class, so accuracy is misleading when classes are unbalanced. The team should measure how often it catches defective parts, which is recall for the defect class, and how often a flagged part really is defective, which is precision. They should also check that the test set contains enough defective parts to estimate these numbers reliably.