Neuron 101

Classification / Support vector machine

Türkçe

Plate39

Unit 4 · Topic 7 of 10

Support vector machine

Hard, 9 min, 8 steps

812162024283236024681012temperature, degreessunny hours
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 8 Days

Many separating lines

The red circles are days when the ice cream sold out, the blue squares days when it did not. Countless lines can be drawn that try to separate the two classes. An SVM looks for the safest of them.

Open in Colab
  1. from operator import mul
  2. def adim_at(w, z, y, lam, eta):
  3. n = len(z)
  4. g = [lam * v for v in w]
  5. for zi, yi in zip(z, y):
  6. f = sum(map(mul, w, zi))
  7. if yi * f < 1:
  8. for k in range(3):
  9. g[k] -= yi * zi[k] / n
  10. return [v - eta * gk
  11. for v, gk in zip(w, g)]
  12. def pegasos(z, y, C, adim=4000):
  13. lam = 1 / (len(z) * C)
  14. w = [0.0, 0.0, 0.0]
  15. for t in range(1, adim + 1):
  16. w = adim_at(w, z, y, lam,
  17. 1 / (lam * t))
  18. return w
C
1
destek
6
ihlal
0