Bitpath

Lesson 1 · Unit 01

Linear regression

Residuals, least squares and what one outlier does

12 exercisesabout 3 min

What you practise

  • Features and targets, a prediction as a dot product, residuals and mean squared error, the best line by least squares and by gradient descent, why features need scaling

Try a question from this lesson

Pick one

Three points: (1, 1), (2, 3), (3, 2). Line A, y = x, passes through one of them. Line B, y = 0.5x + 1, passes through none. Which has the smaller total squared error?

Hint

For each line, work out its miss at x = 1, 2 and 3. Square the three misses and add them.

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Residuals and least squares

A residual is what is left over: the target minus the prediction, one per point.

Least squares picks the line whose squared residuals add up to the smallest total. For a straight line there is exactly one such line, and it can be solved for directly, with no descent steps.

Python
x = np.array([1, 2, 3])
y = np.array([1, 3, 2])
resid = y - (0.5 * x + 1)
print(resid)  # [-0.5  1.  -0.5]
print((resid ** 2).sum())  # 1.5

10 more exercises in the app

  • 4× type the answer
  • 1× fill the blanks
  • 3× multiple choice
  • 1× true or false
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy