Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Explorations › Data detective › lesson 5 of 6

Predict with a line

Fit the straight line that sits closest to all the points, then use it to predict a score from hours of study.

A strong pattern can be turned into a prediction. Draw the straight line that fits the cloud best and read new answers off it.

The line of best fit

A straight line is score=a+b×hours\text{score} = a + b × \text{hours}score=a+b×hours, where bbb is the slope (marks per extra hour) and aaa is where it starts at 0 hours. The best line makes the total of the squared vertical gaps between the points and the line as small as possible: the least-squares line.

Each extra hour of study goes with about 5 to 6 more marks. Slide the hours in the model and the yellow ball reads the same predictions off the black line.

How far to trust it

  • Inside the data (0 to 10 hours) predictions are fair guesses, give or take the scatter, about ±6 marks here.
  • Outside the data the line keeps going but reality does not. At 20 hours the line predicts over 130 marks out of 100.
  • The line describes this class. Another school, another test, another line.

This is exactly what a machine learning model does at its simplest: find the line, or curve, that fits past examples, then use it on new ones.

What to remember

  • The least-squares line minimises the squared gaps between points and line.
  • Its slope is the expected change in output per unit of input.
  • Predictions are reasonable inside the range of the data and unreliable outside it.
  • Fitting a line to examples is the simplest form of machine learning.
Find the patternNext