Linear regression.

Twelve students wrote down how many hours they studied, then sat the same exam. Each dot is one student. A straight line turns hours into a predicted score, and the error measures how far the line misses.

From Chapter 2: Linear Regression, which explains these figures step by step.

Figure

Every miss, and their average

1 hours, score 481.5 hours, score 532 hours, score 503 hours, score 603.5 hours, score 574 hours, score 665 hours, score 685.5 hours, score 756 hours, score 717 hours, score 828 hours, score 839 hours, score 91
  • Student
  • Your line
  • Miss (residual)
Slope w
1.00
Bias b
63.0
Your error (MSE)
119.6
Best possible
?
Drag the two orange handles, or focus one and use the arrow keys.
The red dashed lines are the residuals. The error is the mean of their squares over all twelve students. Try it: get your error below 7. Then reveal the best line and see how close you came.
Figure

Squared error chases outliers

1 hours, score 481.5 hours, score 532 hours, score 503 hours, score 603.5 hours, score 574 hours, score 665 hours, score 685.5 hours, score 756 hours, score 717 hours, score 828 hours, score 83
  • Least squares
  • Least absolute error
  • Movable student
Slope before
5.31
Least squares slope
5.31
Least absolute slope
5.38
Drag the large dark dot anywhere.
Both lines are refitted every time the point moves. The solid line minimises squared error; the dashed line minimises absolute error. Try it: drag the dark dot to the bottom right corner and watch which line follows it.

Learn the ideas behind it

More playgrounds

Search

    The Book of Machine Learning
    Search
    Reading settings
    Text size
    Colours

    Saved in this browser only.

    Keyboard shortcuts
    /
    Search the book
    ← →
    Previous and next chapter
    g
    Glossary
    c
    Table of contents
    e
    Jump to the exercises
    t
    Reading settings
    ?
    Show this list
    Esc
    Close a window or pop-in