Nobody can write down the rules for recognising a face or spotting a fraudulent payment, but a program can learn them from examples. Machine learning comes in three main types, depending on whether the data is labelled and whether the system learns by trial and error. Regression is one of the simplest and most useful methods.
Machine learning is a branch of AI in which a program improves its performance on a task by learning patterns from data, instead of following rules a programmer has written. In supervised learning the training data is labelled with the correct output, and the model learns to map inputs to outputs (classification or regression). In unsupervised learning the data is unlabelled and the model finds its own structure, such as clusters. In reinforcement learning an agent acts in an environment and learns by trial and error to maximise its reward. Regression predicts a continuous value by fitting a line or curve that minimises the error.
Fig. 1: the three categories of machine learning
Section 01
Three ways to learn.
Traditional programs follow rules written by a programmer. A machine learning system is given data and a goal, and builds its own model. What kind of data is available decides which category of learning you use.
Supervised
Unsupervised
Reinforcement
Training data
labelled: each input comes with the correct output
unlabelled: inputs only
no data set; the agent creates experience by acting
What it learns
a mapping from input to output
hidden structure: clusters, associations
a policy: the best action in each state
Typical tasks
classification (spam or not spam), regression (predict a price)
playing games, controlling robots, self-driving manoeuvres
Feedback
error against the known label
none: no right answer is given
reward or penalty after each action
Training and testing: a supervised model is trained on most of the labelled data, then tested on data it has never seen to check that it generalises and has not just memorised the training set.
Reinforcement learning: the agent observes the state, takes an action, receives a reward (positive or negative) and a new state. Over many episodes it learns which actions lead to the greatest total reward, balancing exploration (trying new actions) with exploitation (using actions it knows are good).
Examiner trap
Unsupervised does not mean "no human involved". It means the training data has no labels, so the algorithm must find the groups itself; a human still chooses the data and interprets the clusters.
Section 02
Regression: fitting a line.
Regression is a supervised method that predicts a continuous number (a score, a price, a temperature). Linear regression fits the straight line y = mx + c that best matches the training data. "Best" means the line that makes the total squared error as small as possible: the least squares method.
Residual (error): actual value − predicted value for one training example.
Least squares: choose m and c to minimise the sum of the squared residuals. Squaring stops positive and negative errors cancelling and punishes big errors more.
Formulae: gradient m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)2, and intercept c = ȳ − m x̄, where x̄ and ȳ are the means.
Mean squared error (MSE): the average of the squared residuals; training aims to make it as small as possible.
Hours of revision, x
1
2
3
4
5
Test score, y
52
55
61
64
68
Worked example Least squares by hand
Find the least squares regression line for the data in the table and use it to predict the score after 6 hours of revision.
Means: x̄ = 15 ÷ 5 = 3 and ȳ = 300 ÷ 5 = 60.
Deviations x − x̄: −2, −1, 0, 1, 2. Deviations y − ȳ: −8, −5, 1, 4, 8.
Use the same line to predict the score after 8 hours of revision.
4.1 × 8 + 47.7 = 80.5
Examiner trap
A regression model is only trustworthy inside the range of its training data. Predicting for 40 hours gives 211.7, an impossible score: extrapolating far beyond the data breaks the model.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
Which category of machine learning is trained on labelled data?
Quick check+10 XP
A shop groups its customers by buying habits without deciding the groups in advance. Which method is this?
Quick check+10 XP
In reinforcement learning, what does the agent receive after each action?
Quick check+10 XP
What does a regression model predict?
Section 03
Choosing the method.
Exam questions describe a situation and ask which type of learning fits, and why. Start from the data: is it labelled, unlabelled, or can the system only be scored on what it does?
Why machine learning at all: some tasks (recognising speech, spotting fraud, recommending films) have rules too complex or too numerous to write by hand; a learned model can also adapt as new data arrives and can find patterns people would miss in very large data sets.
Use supervised learning when past examples with known answers exist and you want to predict the answer for new cases: diagnosing a disease from scans labelled by doctors, predicting house prices from past sales.
Use unsupervised learning when there are no labels, or you do not know what groups exist: segmenting customers for marketing, flagging unusual network traffic.
Use reinforcement learning when there is no data set of correct answers but outcomes can be scored, and the task is a sequence of decisions: a game, a robot learning to walk, managing traffic lights.
Your turn
A streaming service wants to group its users into types based on what they watch, without deciding the types in advance. Which category of machine learning should it use?
Unsupervised learning (clustering): the viewing data has no labels and the groups are not known in advance.
Examiner trap
"Supervised" refers to labelled training data, not to a person watching the program run. Justify your choice by describing the data.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to A Level Paper 3 and Paper 4 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
A regression line is y = 4.1x + 47.7. What value does it predict when x = 8?
Exam style+20 XP
Which task is most suited to regression?
Exam style+20 XP
What does the least squares method minimise?
Exam style+20 XP
Why is reinforcement learning suitable for training an AI to play a video game?
Skill unlocked
Machine learning, mastered.
This skill is now recorded on your profile. Keep the chain going.