The shape of the lesson
By the end of the lesson, learners can
- Three ways to learn: Traditional programs follow rules written by a programmer.
- Regression: fitting a line: Regression is a supervised method that predicts a continuous number (a score, a price, a temperature).
- Choosing the method: Exam questions describe a situation and ask which type of learning fits, and why.
- Labelled data: supervised (classification for categories, regression for numbers).
- Unlabelled data: unsupervised (clustering, associations).
- Score actions, no data set: reinforcement (agent, environment, reward, policy).
- Regression: m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)2, c = ȳ − m x̄.
One picture every idea returns to
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.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, 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. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Three ways to learn | Traditional programs follow rules written by a programmer. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Regression: fitting a line | Regression is a supervised method that predicts a continuous number (a score, a price, a temperature). Model the worked example Least squares by hand on the board, one line at a time. Your turn: Use the same line to predict the score after 8 hours of revision. | Pairs |
| 21 to 30 min | Teach and check: Choosing the method | Exam questions describe a situation and ask which type of learning fits, and why. 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? | Corners |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 20 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Choosing the method, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Corners
Put one answer or viewpoint in each corner of the room. Students move to the corner they agree with, justify the choice to a partner there, then hear one voice from each corner before the reveal.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| 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. |
| 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. |
| "Supervised" refers to labelled training data, not to a person watching the program run. | Justify your choice by describing the data. |
Machine learning: supervised, unsupervised and reinforcement: worksheet
6 questions, 20 marks. Written in the style of the papers; no past paper question is reproduced.
State what is meant by machine learning.
Explain the difference between supervised learning and unsupervised learning. Give an example application of each.
Describe how reinforcement learning is used to train a robot to walk.
A company records the years of experience and salary (in thousands) of four employees.
| Years, x | 2 | 4 | 6 | 8 |
|---|---|---|---|---|
| Salary, y | 30 | 34 | 41 | 47 |
Calculate the least squares regression line y = mx + c and use it to predict the salary for 10 years of experience.
For each situation, identify the most suitable category of machine learning: (a) a bank groups transactions to find unusual patterns that may be new types of fraud; (b) a hospital trains a system on X-rays that doctors have already marked as healthy or diseased; (c) a program learns to control the traffic lights at a junction by being scored on how short the queues are.
A teacher fits the line y = 4.1x + 47.7 to data on hours of revision (1 to 5 hours) and test score (out of 100). She uses it to predict the score of a student who revises for 40 hours. Comment on this use of the model.
Answer key and marking notes
- A type of AI in which a program learns from data / experience.
- So it improves its performance at a task without being explicitly programmed with the rules.
- Supervised learning uses labelled training data: each input has the correct output.
- The model learns to predict the output for new inputs, e.g. classifying emails as spam or not spam / predicting prices.
- Unsupervised learning uses unlabelled data, so no correct output is given.
- The model finds patterns or groups itself, e.g. clustering customers by buying habits.
- The robot is the agent; the floor and its body physics are the environment.
- In each state the robot chooses an action (e.g. move a joint) by trial and error.
- It receives a reward for progress (e.g. moving forward) and a penalty for falling.
- Over many attempts it updates its policy to choose actions that maximise its total reward.
- Means x̄ = 5, ȳ = 38.
- Σ(x − x̄)(y − ȳ) = (−3)(−8) + (−1)(−4) + (1)(3) + (3)(9) = 24 + 4 + 3 + 27 = 58; Σ(x − x̄)2 = 9 + 1 + 1 + 9 = 20.
- m = 58 ÷ 20 = 2.9; c = 38 − 2.9 × 5 = 23.5, so y = 2.9x + 23.5.
- For x = 10: y = 29 + 23.5 = 52.5 (thousand).
- (a) Unsupervised learning (clustering / anomaly detection, no labels).
- (b) Supervised learning (labelled X-rays, classification).
- (c) Reinforcement learning (actions scored by a reward, no labelled data).
- The prediction is 4.1 × 40 + 47.7 = 211.7, which is impossible for a test out of 100.
- 40 hours is far outside the range of the training data (1 to 5 hours), so this is extrapolation.
- The relationship is unlikely to stay linear, so the model should only be used within (or close to) the range of its training data.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
Which statement describes reinforcement learning?
- AAn agent acts in an environment and learns from the rewards and penalties it receives
- BA model learns a mapping from inputs to outputs using labelled examples
- CAn algorithm finds hidden groups in data that has no labels
- DA line is fitted to data points by minimising the squared errors
A bank has five years of card transactions, each marked by its investigators as fraudulent or genuine. It wants to flag new transactions that are likely to be fraud. Which category of machine learning fits best?
- ASupervised learning, because every past transaction has a label
- BUnsupervised learning, because fraud is hidden in the data
- CReinforcement learning, because the bank is rewarded for catching fraud
- DUnsupervised learning, because no person watches the model run
The least squares regression line for some training data is found from these values: x̄ = 5, ȳ = 9.5, Σ(x − x̄)(y − ȳ) = 28 and Σ(x − x̄)2 = 20. What value does the line predict when x = 10?
- A16.5
- B14.0
- C23.5
- D30.5
Why is a supervised model tested on labelled data that was not used to train it?
- ATo check that it generalises to new data rather than memorising the training set
- BTo give the model extra examples so that its error keeps falling
- CTo label the test data automatically for the next round of training
- DTo find the clusters in the data before training starts
A regression model predicts y = 2x + 1. It is tested on four points: (1, 4), (2, 4), (3, 8) and (4, 9). What is the mean squared error?
- A0.75
- B0.25
- C3
- D0.5
A delivery robot learns by reinforcement learning. After many episodes it always takes the same corridor, which it has found gives a good reward, and never tries other corridors. Which statement best evaluates this behaviour?
- AIt is exploiting too much: without exploration it may never find a better route
- BIt is exploring too much: it should stop trying new corridors
- CIt has overfitted because its labelled training data was too small
- DIt shows the reward function is wrong, as rewards should only be negative
Quiz key
Reinforcement learning has no training data set: the agent takes actions, receives a reward or penalty and a new state, and learns a policy that maximises total reward. Learning from labelled examples is supervised learning, finding groups in unlabelled data is unsupervised learning (clustering), and fitting a least squares line is linear regression, a supervised method.
Each past transaction is labelled fraudulent or genuine, so a classifier can be trained on labelled data and then predict the label of new transactions: supervised learning. Fraud being hard to see does not make the data unlabelled. There is no agent taking a sequence of actions for rewards here. And supervised refers to labelled data, not to a person watching the program.
m = 28 ÷ 20 = 1.4 and c = 9.5 − 1.4 × 5 = 2.5, so y = 1.4x + 2.5 and at x = 10, y = 14 + 2.5 = 16.5. 14.0 leaves out the intercept, 23.5 uses c = 9.5 (the mean of y) instead of 2.5, and 30.5 adds m x̄ instead of subtracting it, giving c = 16.5.
Testing on unseen data shows whether the model has learned the general pattern and will work on new cases; a model that only memorised the training data (overfitting) does badly here. Test data is not used to train the model, the labels already exist, and finding clusters is an unsupervised task, not part of testing a supervised model.
Predictions are 3, 5, 7 and 9, so the residuals are 1, −1, 1 and 0. Their squares are 1, 1, 1 and 0, which total 3, and 3 ÷ 4 = 0.75. 0.25 is the mean of the residuals without squaring (the 1 and −1 cancel), 3 is the sum of the squares without dividing by the number of points, and 0.5 divides by 6 instead of 4.
Always choosing the known good action is pure exploitation; a better corridor would only be found by exploring other actions sometimes, so the agent should keep some exploration. It is the opposite of exploring too much. Reinforcement learning uses no labelled training data, so overfitting to a small labelled set does not apply. Rewards can be positive or negative, and a positive reward for good routes is correct.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.