Set the height at the average, then turn the tilt

Put the line through the average outcome at the middle input, then change its tilt one step at a time until either step makes the total squared error larger

Height first, then tilt

012340510Flat
The dashed gaps from each point to a flat line at height 3.

Fit the line shows five points at inputs 0 to 4 and a line with two controls: its height at input 2, and how much it changes for each 1 across.

More

You move it until the total squared error is as small as it can be: each point's gap up or down to the line, squared, then added. Then you read a prediction from the line.

Set the height first. The inputs are centered on 2, so the best line passes through the average of the five outcomes at input 2: add them and divide by five. Then change the tilt one step at a time and watch the total. When a step either way makes it larger, stop.

Squaring makes a large miss count much more than a small one: a gap of 1 adds 1, a gap of 2 adds 4, a gap of 5 adds 25. So a line that runs through four points but misses the fifth by a lot can lose to a line that misses all five by a little.

1Height at input 2: the average outcome.

2Change the tilt one step at a time.

3Stop when a step either way raises the total.

Lesson help

Put the line through the average outcome at the middle input, then turn the tilt until both steps make the total larger.

About this lesson

Try the method in a practice when you are ready.

Report

Height first, then tilt

Fit the line shows five points at inputs 0 to 4 and a line with two controls: its height at input 2, and how much it changes for each 1 across. You move it until the total squared error is as small as it can be: each point's gap up or down to the line, squared, then added. Then you read a prediction from the line.

Set the height first. The inputs are centered on 2, so the best line passes through the average of the five outcomes at input 2: add them and divide by five. Then change the tilt one step at a time and watch the total. When a step either way makes it larger, stop.

Squaring makes a large miss count much more than a small one: a gap of 1 adds 1, a gap of 2 adds 4, a gap of 5 adds 25. So a line that runs through four points but misses the fifth by a lot can lose to a line that misses all five by a little.

1Height at input 2: the average outcome.

2Change the tilt one step at a time.

3Stop when a step either way raises the total.

012340510Flat
The dashed gaps from each point to a flat line at height 3.

A useful compromise

The outcomes 2, 1, 3, 3 and 6 add to 15, so the height at input 2 is 15 ÷ 5 = 3. With the line flat the total squared error is 1 + 4 + 0 + 0 + 9 = 14.

Tilting up brings it down. At a change of 1 for each 1 across the total is 4, and a step either way, to 0.75 or 1.25, raises it to 4.625. So the best line has height 3 and change 1, though no line passes through every point.

012340510Best
Height 3 at input 2, change 1: a total of 4.

One point stands apart

The outcomes are 3, 3.5, 9, 4.5 and 5. Line A has height 4 and change 0.5 and runs exactly through four of the points. Line B has the same change at height 5.

012340510AB
Line A is solid; line B is dashed.

Try it

Which line has the smaller total squared error?

  1. Line A, through four points
  2. Line B, at height 5
Show the answer

Line B, at height 5

Right. The average outcome is 25 ÷ 5 = 5, so the best line passes through 5 at input 2. Line B's total is 20, against line A's 25 from its one large miss.

Enable JavaScript to answer interactively and save your place.

Practice Fit the line

Sign in free

Practice without limits and keep your progress.