LearnMachine learning

Linear regression

Find the straight line that best fits your data, and see why one odd point can pull it off course.

  • Machine learning
  • Supervised
  • Regression

Click to add a point, drag to move it, drag it off the chart to remove it.

How it works

The best line has the smallest squared error.

Linear regression predicts a number from another number with a straight line: prediction = slope × input + intercept. For example, a house price from its size.

For each point, the gap between the real value and the line is its error. Squaring the gaps makes big misses count much more, and the best line is the one where the squares add up to the smallest total. There is an exact formula for it, which is why the line jumps straight to the answer as you move the points.

Because errors are squared, a single point far from the rest can drag the whole line towards it. That is why outliers deserve a careful look before you trust a model.