Neuron 101

Learning from examples / Writing rules and learning from examples

Türkçe

Plate22

Unit 3 · Topic 1 of 11

Writing rules and learning from examples

Easy, 6 min, 8 steps

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

Step 1 of 8 Rule

The ice cream seller's rule

The ice cream seller picks how many ice creams to prepare for tomorrow with a rule: if it is colder than 21 degrees, 28, otherwise 47. A person wrote this rule.

Open in Colab
  1. def kural(t):
  2. if t < 21:
  3. return 28
  4. return 47
  5. x = [12, 15, 18, 20, 23, 26, 29, 32]
  6. y = [25, 26, 35, 33, 42, 48, 48, 56]
  7. n = len(x)
  8. xo = sum(x) / n
  9. yo = sum(y) / n
  10. pay = sum((a - xo) * (b - yo)
  11. for a, b in zip(x, y))
  12. payda = sum((a - xo) ** 2 for a in x)
  13. w = pay / payda
  14. b = yo - w * xo
  15. print(kural(27), w * 27 + b)
esik
21
w
1.59
b
4.43
tahmin
47.25