QuiddityML

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 False

This 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.

Traditional programming turns rules plus data into output through a program, while machine learning turns data plus labels into learned rules through training

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 24

The 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.

A line through the training points at x equals 2, 4, and 6 extends to x equals 12, a point never in the training data, where the learned rule y equals 2x gives 24

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.

Several different curves, including the straight line y equals 2x, all pass exactly through the two points (1, 2) and (3, 6)

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.

Data as input and signal pairs, with four examples: house features and sale price, an email and a spam label, a sequence of words and the next word, a game state and 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.

The five categories of machine learning drawn as overlapping circles: supervised, unsupervised, semi-supervised, self-supervised, and reinforcement learning, each with a short description

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?"

A decision tree starting from the question of what data you have, leading to supervised, semi-supervised, self-supervised, or unsupervised learning, each with one example

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.

A language model gets different category names depending on its training signal: next-token pretraining is self-supervised or, by some, unsupervised, and answer fine-tuning is supervised

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.

Two algorithms that each score 80 on two problems and 20 on the other two, giving the same average performance across all four

Common mistakes when starting out

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.