Week 01 lab · 2D classification

Interactive perceptron

Give the model examples from two groups. Pick a class, then click the graph or enter coordinates. The model retrains after every new point.

Live training
Class −1 Class +1 Boundary
-6-6-4-4-2-200224466xyPoint 1: (-4, -2), Class −1Point 2: (-3, 1), Class −1Point 3: (-1.5, -3.5), Class −1+Point 4: (1, 2.5), Class +1+Point 5: (3, 1), Class +1+Point 6: (4, 4), Class +1

Click anywhere inside the graph to add the selected class.

Pseudocode

How it learns.

weights ← [0, 0]
bias ← 0

repeat up to 100 times:
  mistakes ← 0

  for each point:
    score ← w₁x + w₂y + bias
    guess ← +1 if score ≥ 0, otherwise −1

    if the guess is wrong:
      weights ← weights + label × [x, y]
      bias ← bias + label
      mistakes ← mistakes + 1

  stop when mistakes = 0