Do more revision hours mean better marks?
Five pupils tell their teacher how many hours they revised. They also share their test marks. The points on a graph look like a rising cloud.
Can you draw one straight line through the cloud, and use it to guess the mark for 6 hours? That is what regression does.
Key words
| Word | What it means | Example |
|---|---|---|
| Regression | finding the line that best describes how one value changes with another | |
| Input value | the value you know or choose, drawn along the bottom, called x | Hours revised |
| Output value | the value you want to predict, drawn up the side, called y | Test mark |
| Slope | how much the output changes for each step in the input | |
| Intercept | the output value where the line crosses the up axis, when the input is 0 | |
| Least squares | the method that picks the line with the smallest total of squared gaps to the points | |
| Correlation | two values rise or fall together, which does not prove one causes the other |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can say what regression is and when it is used. I can work out a simple line and use it to predict.
Starter
Have a go
Starter
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
The five pupils
| Pupil | Hours revised (x) | Test mark (y) |
|---|---|---|
| A | 1 | 2 |
| B | 2 | 4 |
| C | 3 | 5 |
| D | 4 | 4 |
| E | 5 | 5 |
The cells students fill in are left blank in this preview.
What regression is for
Regression fits a line to data. Use it when you want to predict one value from another, or to say how strongly they move together.
The line has two numbers: the slope and the intercept. The prediction is the intercept plus the slope times the input.
Worked example: the line for five pupils
| Step | Working | Result |
|---|---|---|
| Mean of x | 1+2+3+4+5 is 15, divided by 5 | 3 |
| Mean of y | 2+4+5+4+5 is 20, divided by 5 | 4 |
| Top of the slope | Add (x-3) times (y-4) for each pupil: 4 + 0 + 0 + 0 + 2 | 6 |
| Bottom of the slope | Add (x-3) times (x-3): 4 + 1 + 0 + 1 + 4 | 10 |
| Slope | 6 divided by 10 | 0.6 |
| Intercept | 4 take away 0.6 times 3 | 2.2 |
| Prediction for 6 hours | 2.2 plus 0.6 times 6 | 5.8 |
The cells students fill in are left blank in this preview.
Try it: the line in Python
xs = [1, 2, 3, 4, 5]
ys = [2, 4, 5, 4, 5]
x_mean = sum(xs) / len(xs)
y_mean = sum(ys) / len(ys)
top = 0
bottom = 0
for i in range(len(xs)):
top = top + (xs[i] - x_mean) * (ys[i] - y_mean)
bottom = bottom + (xs[i] - x_mean) ** 2
slope = top / bottom
intercept = y_mean - slope * x_mean
print("slope", slope)
print("intercept", intercept)
print("6 hours:", intercept + slope * 6)
Real charts and trend lines
Important
A spreadsheet can draw a scatter chart and add a trend line with one click. This platform has no charting tool, so the line is worked out by the numbers above.