Neuron 101

Learning from examples / Overfitting and underfitting

Türkçe

Plate31

Unit 3 · Topic 10 of 11

Overfitting and underfitting

Medium, 8 min, 8 steps

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

Step 1 of 8 Data

Training and validation

The black dots are eight training days, the blue dots three validation days. The model learns from the training days and is checked on the validation days. The model is a polynomial; its degree sets how flexible it is.

Open in Colab
  1. import numpy as np
  2. x = np.array([12, 15, 18, 20,
  3. 23, 26, 29, 32])
  4. y = np.array([25, 26, 35, 33,
  5. 42, 48, 48, 56])
  6. xd = np.array([16, 25, 31])
  7. yd = np.array([30, 44, 52])
  8. t, td = (x - 22) / 10, (xd - 22) / 10
  9. for d in range(8):
  10. c = np.polyfit(t, y, d)
  11. p = np.polyval(c, t)
  12. q = np.polyval(c, td)
  13. e = np.mean((p - y) ** 2)
  14. v = np.mean((q - yd) ** 2)
  15. print(d, e, v)
d
2
egitim
4.26
dogrulama
1.12