Skip to main content
Module 1 · Lesson 2 of 42/56 in the course~20 min
Module lessons (2/4)

Types of learning problems

The hook: one question decides everything

Before choosing any algorithm, ask: do I have the answer for my past examples?

  • If every example comes with the answer you want to predict, you can learn from those answers: supervised learning.
  • If you only have raw data and want to discover its structure, you are in unsupervised learning.
  • If an agent learns by acting and receiving rewards, it is reinforcement learning.

Supervised, unsupervised and reinforcement compared

Learning paradigmPast answer (label)?Typical outputExamples
Supervised classificationYes (category)Discrete class or probabilityFraud detection, image tag
Supervised regressionYes (number)Continuous quantityHouse price, travel time
Unsupervised learningNo labelsCluster IDs or low-dim axesCustomer segments, anomaly score
Reinforcement learningDelayed reward signalPolicy of actionsGame playing, robotics control

Supervised learning

The examples are pairs: an input and the correct output (the label). The model learns the mapping from inputs to outputs, then predicts outputs for new inputs. There are two flavours:

  • Classification: the output is a category (spam or not spam, which digit, which species).
  • Regression: the output is a number (a price, a temperature, a delivery time).

A quick test: if it makes sense to ask "how far off was the prediction?", it is regression. If the answer is simply right or wrong (or a probability per category), it is classification.

Unsupervised and reinforcement learning

In unsupervised learning, there are no labels. The model looks for structure by itself: groups of similar customers (clustering), the main directions of variation (dimensionality reduction), unusual items (anomaly detection). Because there is no answer key, judging the result takes more care.

In reinforcement learning, an agent takes actions in an environment and receives rewards. It learns a strategy that maximises the total reward over time, like a program learning to play a game. It needs an interactive environment, so it sits outside the tabular scope of this course.

Seeing the difference in Python

In classification, target values are discrete class labels, and we evaluate exact agreement:

Python
import numpy as np

y_true = np.array([0, 1, 1, 0])
y_pred = np.array([0, 1, 0, 0])
print("classification accuracy:", float((y_true == y_pred).mean()))  # 0.75

In regression, predictions are continuous floats, so we measure how far off predictions sit on average:

Python
y_price = np.array([150.0, 260.0, 410.0])
y_hat = np.array([160.0, 250.0, 390.0])
mae = float(np.abs(y_price - y_hat).mean())
print("mean absolute error:", round(mae, 2))  # 13.33

Turning the same continuous column into a threshold flag switches a regression dataset into classification:

Python
prices = np.array([150, 260, 410, 190])
is_expensive = (prices >= 250).astype(int)
print(is_expensive.tolist())  # [0, 1, 1, 0]

And in unsupervised clustering, we pass only X (y does not exist) and inspect centroids or nearest distances:

Python
X_points = np.array([[1.0, 1.0], [1.2, 0.9], [8.0, 8.2]])
centroid_a = np.array([1.1, 0.95])
dists = np.linalg.norm(X_points - centroid_a, axis=1)
print([round(float(d), 2) for d in dists])  # [0.11, 0.11, 10.01]

Try it: sort the problems

Practice: targets and errors by task type

Practice Stage

Warmup — Binary label conversion

Exercise#machine-learning.m1.l2.e1
Attempts: 0Loading…

Turn delivery_minutes into a binary classification label vector y_late (1 where minutes > 30, else 0) as plain ints.

Loading editor…
Show hint

Use (delivery_minutes > 30).astype(int) so 30 itself stays 0.

Solution available after 3 attempts

Practice Stage

Practice — Numeric error vs. exact class match

Exercise#machine-learning.m1.l2.e2
Attempts: 0Loading…

Compute the Mean Absolute Error between true numeric temperatures y_true and predictions y_pred. Store it as a float in mae.

Loading editor…
Show hint

np.abs(y_true - y_pred).mean() averages the absolute error magnitude.

Solution available after 3 attempts

Practice Stage

Challenge — Nearest cluster without labels

Exercise#machine-learning.m1.l2.e3
Attempts: 0Loading…

For each 2-D point in X, assign cluster label 0 if it is closer to center_0, else 1. Store the integer cluster assignments in clusters.

Loading editor…
Show hint

Compute distances d0 and d1 using np.linalg.norm(..., axis=1), then check (d1 < d0).astype(int).

Solution available after 3 attempts

Check your understanding

Quiz#machine-learning.m1.l2.e4

You have 10,000 past loan applications, each marked 'repaid' or 'defaulted'. You want to predict the outcome for new applications. What is this?

Answer options
Quiz#machine-learning.m1.l2.e5

You have customer purchase histories and no labels, and you want to find groups of similar customers. What do you use?

Answer options
Quiz#machine-learning.m1.l2.e6

Which of these is a regression problem?

Answer options
Quiz#machine-learning.m1.l2.e7

Why is reinforcement learning not a good fit for predicting house prices from a table of past sales?

Answer options