A Level · Topic 18.1
A-Level Computer Science 9618 / Topic 18 / A2

Learning from data.

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.

The key idea

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.

SupervisedUnsupervisedReinforcement Agent Environment actionreward+ state labelled exampleslearn input → output unlabelled datafind groups / patterns trial and errormaximise total reward
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.

SupervisedUnsupervisedReinforcement
Training datalabelled: each input comes with the correct outputunlabelled: inputs onlyno data set; the agent creates experience by acting
What it learnsa mapping from input to outputhidden structure: clusters, associationsa policy: the best action in each state
Typical tasksclassification (spam or not spam), regression (predict a price)clustering customers, finding items bought together, detecting anomaliesplaying games, controlling robots, self-driving manoeuvres
Feedbackerror against the known labelnone: no right answer is givenreward or penalty after each action
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.

Hours of revision, x12345
Test score, y5255616468
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.
  1. Means: x̄ = 15 ÷ 5 = 3 and ȳ = 300 ÷ 5 = 60.
  2. Deviations x − x̄: −2, −1, 0, 1, 2. Deviations y − ȳ: −8, −5, 1, 4, 8.
  3. Σ(x − x̄)(y − ȳ) = 16 + 5 + 0 + 4 + 16 = 41 and Σ(x − x̄)2 = 4 + 1 + 0 + 1 + 4 = 10.
  4. m = 41 ÷ 10 = 4.1 and c = 60 − 4.1 × 3 = 47.7, so y = 4.1x + 47.7.
  5. Predictions 51.8, 55.9, 60.0, 64.1, 68.2 give residuals 0.2, −0.9, 1.0, −0.1, −0.2; MSE = 1.9 ÷ 5 = 0.38.
  6. For x = 6: y = 4.1 × 6 + 47.7 = 72.3.
Answer: y = 4.1x + 47.7; predicted score 72.3
Your turn
Use the same line to predict the score after 8 hours of revision.
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?

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

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Supervised, unsupervised and reinforcement learning, reasons for using each, and linear regression by least squares.