24 September 2026 · 8 min read
What is machine learning? The 5 types of learning explained
Machine learning is a way to build software that learns its rules from examples instead of having them written by hand. This post explains how that works and why it can work on data the model has never seen, then walks through the five types of learning (supervised, unsupervised, semi-supervised, self-supervised, and reinforcement learning) with an example of each and how to pick between them.
Machine learning is a way to build software that learns its rules from examples instead of having a programmer write them. You show a model many inputs together with the outputs you want, and training adjusts the model until it produces those outputs by itself. It is how spam filters, product recommendations, speech recognition, and chatbots work, and it is useful whenever the rules are too many or too fuzzy to write down by hand. Most machine learning falls into five types (supervised, unsupervised, semi-supervised, self-supervised, and reinforcement learning), and they differ in one thing: where the signal the model learns from comes from.
How machine learning differs from traditional programming
In traditional programming, a person writes the rules and the computer applies them to data. A spam filter built that way is a growing list of conditions:
1def is_spam(email, contacts):
2 if "free money" in email.text:
3 return True
4 if "click here" in email.text:
5 return True
6 if email.sender not in contacts:
7 return True
8 # ... hundreds more rules
9 return FalseThis kind of filter keeps breaking. Spammers change their wording, each new trick needs a new rule, and the rules start to contradict each other.
Machine learning turns the process around. Instead of rules and data going in and an output coming out, data and the desired outputs go in and the rules come out. You collect thousands of emails, each one labeled "spam" or "not spam", and a training algorithm adjusts the model's parameters (the numbers inside the model that decide its output) until its predictions match those labels as closely as it can. Nobody writes a single spam rule.

Why can a model work on data it has never seen?
A model trained on 10,000 emails is only useful if it also gets the 10,001st email right. Using a pattern learned from a limited set of examples to make correct predictions on new inputs is called generalization, and it is the reason to train a model at all.
A small example shows how it works. Suppose the true rule is $y = 2x$, and the model only sees three examples: $(2, 4)$, $(4, 8)$, and $(6, 12)$. If the model is a straight line, $y = wx + b$ with parameters $w$ and $b$, training can recover $w = 2$ and $b = 0$. Given $x = 12$, which never appeared in training, it predicts $24$. Here is that model trained in PyTorch:
1import torch
2
3# Three (x, y) examples of a rule the model never sees: y = 2x
4x = torch.tensor([[2.0], [4.0], [6.0]])
5y = 2 * x
6
7model = torch.nn.Linear(1, 1) # prediction = w * x + b
8optimizer = torch.optim.SGD(model.parameters(), lr=0.02)
9
10for step in range(2000):
11 optimizer.zero_grad()
12 loss = torch.nn.functional.mse_loss(model(x), y)
13 loss.backward()
14 optimizer.step()
15
16print(f"w = {model.weight.item():.3f}, b = {model.bias.item():.3f}") # close to 2 and 0
17print(f"prediction for x = 12: {model(torch.tensor([[12.0]])).item():.2f}") # close to 24The loop repeats one step 2,000 times: the model predicts, the loss (here the mean squared error, one number measuring how far the predictions are from the true values) is computed, and the optimizer nudges $w$ and $b$ to make the loss smaller. If the loss does not shrink, the learning rate lr is the first thing to change.

Generalization is not guaranteed. Even with only two points, $(1, 2)$ and $(3, 6)$, infinitely many curves pass through both, and the data alone cannot say which one is true. The model picks one because of the assumptions built into it, called its inductive bias. A linear model assumes straight lines, a decision tree assumes the answer can be found by a series of yes/no questions on the features, and a nearest-neighbour model assumes that similar inputs get similar answers. When the assumption fits the problem, the model generalizes. When it does not, the model fits the training data and fails on new data.

What a model learns from
Every kind of machine learning needs data, and the data comes as pairs of an input and a signal. The input is what the model sees. The signal is what tells the model whether its output was good.
- House price prediction: the input is a house's features, and the signal is its sale price.
- Spam filtering: the input is an email, and the signal is the spam or not-spam label.
- Language modeling: the input is a sequence of words, and the signal is the word that actually came next.
- Game playing: the input is the state of the game, and the signal is a reward score.

The signal does not have to be a label a person wrote. It has to exist, because training compares the model's output with the signal to compute the loss. It also has to be accurate: if 10% of the "spam" labels are wrong, the model learns those mistakes too, and a large noisy dataset can teach a model something confidently wrong.
The five types of machine learning are five answers to the question of where that signal comes from.
The five types of machine learning
Supervised learning
In supervised learning, every training example comes with a label, the correct answer written down in advance. The model learns to predict the label from the input. The spam filter and the $y = 2x$ example above are both supervised. Predicting a number (a price, a temperature) is called regression, and predicting a category (spam or not, cat or dog) is called classification. Supervised learning is usually the first choice whenever good labels exist, and its main cost is getting those labels, which often means people annotating data by hand.
Unsupervised learning
In unsupervised learning, there are no labels at all, and the model looks for structure in the inputs themselves. A common example is clustering: grouping customers by their purchase history so that customers who buy similar things end up in the same group, without anyone saying in advance what the groups should be. Another is reducing a dataset with hundreds of features to a handful that keep most of the information. The signal here is the structure already present in the data.
Semi-supervised learning
Semi-supervised learning is for the common case of a little labeled data and a lot of unlabeled data, say 100 labeled images and 10,000 unlabeled ones. The model uses the labels where they exist and the structure of the unlabeled data for the rest. One common method is pseudo-labeling: train on the 100 labeled images, predict labels for the unlabeled ones, keep the predictions the model is most confident about as new labels, and train again on the larger set.
Self-supervised learning
Self-supervised learning has no human labels either, but it builds a prediction task out of the data itself, so the data provides its own targets. Large language models are trained this way: the input is a piece of text, and the target is the next word, which is already in the text. BERT, a well-known language model, was trained with masked language modeling: some words in a sentence are hidden and the model predicts them from the words around them. The same idea works for images by hiding patches of an image and predicting what was there. Self-supervised learning is how models learn from very large amounts of raw text and images that nobody could label by hand.
Reinforcement learning
In reinforcement learning, there is no fixed dataset. An agent takes actions in an environment, and the environment responds with a new state and a reward, a number saying how good the result was. A game-playing agent, for example, moves a piece, sees the new board, and receives a reward when it wins. The agent learns which actions lead to high rewards over time. Rewards often arrive late (a game is won or lost only at the end), so a large part of the difficulty is working out which earlier actions deserve the credit.

Which type should you use?
The practical question is rarely "which category is this problem?" and more often "what can I do with the data I have?"
- Plenty of good labeled data: supervised learning. Thousands of labeled cat and dog photos, train a classifier.
- A little labeled data and a lot of unlabeled data: semi-supervised learning.
- No labels, but a prediction task you can build from the data: self-supervised learning, such as masked language modeling on raw text.
- No labels and no prediction task: unsupervised learning, such as clustering customers.
- No dataset, but an environment that gives rewards for actions: reinforcement learning.

The categories overlap
These labels describe how a model is trained at one stage, not what the model is forever. A chat assistant is usually trained in several stages: first self-supervised on large amounts of text to predict the next word, then supervised on examples of good answers written by people, and often then with reinforcement learning from human feedback, where people's preferences between answers act as the reward. Some people call next-word prediction unsupervised, because no human wrote labels, and others call it self-supervised, because the text supplies the targets. The name matters less than the mechanism: what signal the model learns from, and where that signal comes from.

Is there a best machine learning algorithm?
No single algorithm is best for every problem. The no free lunch theorem makes this precise for a specific setup: averaged over all possible problems, every learning algorithm performs equally well, so an algorithm that wins on one kind of problem must lose on another. In practice this is the inductive bias from earlier. Each algorithm assumes something about the data, and it works well when that assumption matches the problem. Choosing a model is choosing which assumptions fit your data.

Common mistakes when starting out
- Choosing the model before looking at the data. What signal you have (labels, a few labels, structure, rewards) decides the type of learning before any model is chosen.
- Expecting more data to fix bad labels. A larger dataset with the same share of wrong labels teaches the same mistakes with more confidence. Checking a sample of the labels by hand is usually worth the time.
- Training on data that does not match where the model will be used. A fraud model trained on transactions from five years ago can miss today's fraud patterns, and a medical model trained at one hospital can fail at another.
- Treating the categories as rigid boxes. Many real systems combine several types of learning, and the useful question is what each training stage learns from.
QuiddityML teaches this as the first concepts of its ML Foundations track, and the exercises on them include telling traditional programming apart from machine learning, naming the type of learning that trains on rewards instead of labels, and picking out the one thing a model needs before it can train at all.