Machine Learning

Types of Machine Learning: Supervised, Unsupervised, Semi-Supervised and Reinforcement

TGTeam GyaniPanditNovember 19, 20264 min read

Machine learning algorithms are usually grouped by how they learn: whether they are given the correct answers (labels) while learning, only some answers, or no answers at all, or whether they learn by trial and error. The four main types are supervised, unsupervised, semi-supervised and reinforcement learning. A fifth idea, self-supervised learning, is behind today’s large language models.

Types of machine learning

Types of Machine Learning at a Glance

Type Learns from Typical tasks Examples
Supervised Labelled data (input + correct answer) Classification, regression Spam detection, house price prediction
Unsupervised Unlabelled data Clustering, association, anomaly detection Customer groups, “bought together” products
Semi-supervised A little labelled + a lot of unlabelled data Classification with few labels Labelling large photo or document collections
Reinforcement Rewards and penalties from an environment Decision-making, control Game-playing agents, robot movement

1. Supervised Learning

The model is trained on examples where we already know the answer. It learns the link between inputs and outputs, then predicts answers for new inputs.

  • Classification: the output is a category. Is this email spam or not? Will the student pass or fail?
  • Regression: the output is a number. What will this flat sell for? How many units will we sell next month?

Common algorithms: linear and logistic regression, k-nearest neighbours (k-NN), decision trees, random forests, support vector machines, naive Bayes and neural networks.

A Tiny Supervised Example in Python

Here a 1-nearest-neighbour model predicts pass/fail from study hours and attendance, using a few labelled examples. Real projects use libraries such as scikit-learn, but this shows the idea in plain Python:

students = [
    ((1, 50), "fail"),
    ((2, 60), "fail"),
    ((3, 65), "fail"),
    ((5, 80), "pass"),
    ((6, 85), "pass"),
    ((8, 90), "pass"),
]   # ((hours of study per day, attendance %), result)

def distance(a, b):
    return ((a[0] - b[0]) ** 2 + ((a[1] - b[1]) / 10) ** 2) ** 0.5

def predict(new):
    nearest = min(students, key=lambda s: distance(s[0], new))
    return nearest[1]

for new in [(4, 75), (2, 55), (7, 88)]:
    print(new, "->", predict(new))

Output:

(4, 75) -> pass
(2, 55) -> fail
(7, 88) -> pass

The model never saw these three students, but it predicts their result from the most similar labelled example. That is supervised learning in a nutshell.

2. Unsupervised Learning

The data has no labels. The model looks for structure on its own.

  • Clustering: grouping similar items, such as customer segments by buying habits.
  • Association rules: finding items that occur together, as in “people who bought bread also bought butter”.
  • Anomaly detection: spotting unusual data, such as a strange login or a faulty sensor reading.
  • Dimensionality reduction: compressing many features into a few (for example, PCA).

A Tiny Clustering Example

Here a simple version of the k-means algorithm splits marks into two groups without being told which group any mark belongs to:

marks = [35, 42, 38, 88, 91, 79, 45, 85]
c1, c2 = min(marks), max(marks)        # starting centres
for _ in range(10):
    g1 = [m for m in marks if abs(m - c1) <= abs(m - c2)]
    g2 = [m for m in marks if abs(m - c1) > abs(m - c2)]
    c1, c2 = sum(g1) / len(g1), sum(g2) / len(g2)
print(sorted(g1), round(c1, 1))
print(sorted(g2), round(c2, 1))

Output:

[35, 38, 42, 45] 40.0
[79, 85, 88, 91] 85.8

3. Semi-Supervised Learning

Labelling data is slow and expensive; a doctor labelling X-rays, for instance. Semi-supervised learning uses a small labelled set together with a large unlabelled set. The model learns from the labelled part and uses the patterns in the unlabelled part to improve. It is common in image, speech and text tasks.

4. Reinforcement Learning

An agent takes actions in an environment and receives rewards or penalties. Over many attempts it learns a strategy that earns the most reward, much like a child learning to ride a bicycle. Reinforcement learning is used in game-playing programs, robotics, recommendation systems and resource management, and a variant using human feedback is used to fine-tune chatbots.

What About Self-Supervised Learning?

In self-supervised learning, the data provides its own labels. For example, a language model hides the next word of a sentence and learns to predict it, over billions of sentences, with no human labelling. This is how large language models learn language before they are fine-tuned. It is often counted as a special case of unsupervised or supervised learning.

How to Choose the Right Type

  • You have historical data with the right answers and want to predict them for new cases: supervised.
  • You have data without answers and want to discover groups or unusual items: unsupervised.
  • You have a few labels and lots of unlabelled data: semi-supervised.
  • Your system must make a series of decisions and learn from the outcome: reinforcement.

Frequently Asked Questions

What are the 4 types of machine learning?

Supervised, unsupervised, semi-supervised and reinforcement learning.

What is the difference between supervised and unsupervised learning?

Supervised learning trains on labelled data (with correct answers); unsupervised learning finds patterns in data without labels.

Is clustering supervised or unsupervised?

Unsupervised, because the groups are not given in advance.

Related: machine learning vs AI · what is machine learning · learn machine learning with Python

Turn reading into skillsCertificate courses in AI, Data Science and programming.
Explore Courses