Neuron 101

Learning from examples / Least squares

Türkçe

Plate26

Unit 3 · Topic 5 of 11

Least squares

Medium, 8 min, 9 steps

05101520253035010203040506070temperature, degreesice creams sold
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 9 Data

Eight days

The same eight days. In the loss function topic we tuned the line by hand; now we will compute the line with the smallest loss without any trial.

Open in Colab
  1. x = [12, 15, 18, 20, 23, 26, 29, 32]
  2. y = [25, 26, 35, 33, 42, 48, 48, 56]
  3. n = len(x)
  4. xo = sum(x) / n
  5. yo = sum(y) / n
  6. sxy = sum((a - xo) * (c - yo)
  7. for a, c in zip(x, y))
  8. sxx = sum((a - xo) ** 2 for a in x)
  9. w = sxy / sxx
  10. b = yo - w * xo
  11. print(w, b)
w
1.59
b
4.43
mse
4.31