Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.6: Regression: the line that fits the data

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

65 minutes

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

WordWhat it meansExample
Regressionfinding the line that best describes how one value changes with another
Input valuethe value you know or choose, drawn along the bottom, called xHours revised
Output valuethe value you want to predict, drawn up the side, called yTest mark
Slopehow much the output changes for each step in the input
Interceptthe output value where the line crosses the up axis, when the input is 0
Least squaresthe method that picks the line with the smallest total of squared gaps to the points
Correlationtwo 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The five pupils

PupilHours revised (x)Test mark (y)
A12
B24
C35
D44
E55

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

StepWorkingResult
Mean of x1+2+3+4+5 is 15, divided by 53
Mean of y2+4+5+4+5 is 20, divided by 54
Top of the slopeAdd (x-3) times (y-4) for each pupil: 4 + 0 + 0 + 0 + 26
Bottom of the slopeAdd (x-3) times (x-3): 4 + 1 + 0 + 1 + 410
Slope6 divided by 100.6
Intercept4 take away 0.6 times 32.2
Prediction for 6 hours2.2 plus 0.6 times 65.8

The cells students fill in are left blank in this preview.

Try it: the line in Python

Code: 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.

The lesson goes on

6 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.