Perceptron Playground

5 / sec
Epoch 0 Updates 0 Mistakes 0 / 0

A perceptron separates two classes with a straight line. Pick a dataset, then press Step to watch it learn one example at a time.

Data
+1 −1 misclassified w points to the +1 side
Click the plot to add a point · drag to move · click a point to flip it
Edit points as numbers
#x1x2y

Training data

Update log

UpdateEpochPointxy zŷ w1w2b

Press Step to train on one point. Each update shows up here, with the weights after it.

Weights & bias
Last update
Mistakes during training
More settings
epochs

How it works

1. Compute a weighted sum

Each example has two inputs, x1 and x2: its position in the plot. The perceptron multiplies each input by its weight, adds them up, and adds the bias:

z = w1x1 + w2x2 + b

2. Apply the activation

The prediction is ŷ = f(z). With the default sign activation, ŷ = +1 if z ≥ 0 and −1 otherwise (here sign(0) = +1). The decision boundary is the set of points where z = 0: the dark line in the plot. For two inputs it is always a straight line, and w points toward the +1 side.

3. Update when wrong

For each training example (one update), the perceptron learning rule nudges every weight:

wi ← wi + η (y − ŷ) xi     b ← b + η (y − ŷ)

If the prediction is right, y − ŷ = 0 and nothing changes. If it's wrong, the boundary moves toward classifying that point correctly. One pass through all the examples is an epoch.

With sigmoid, tanh, or no activation, the update also multiplies by the slope f′(z) (gradient descent on squared error), so weights keep changing a little even for correct points. No regularization is used.

Things to try

  • Train on AND and OR one Step at a time. Which examples cause updates?
  • Turn off the bias and try AND again. Why does it fail?
  • Try XOR. Can any straight line separate it? What happens to the boundary as training goes on?
  • Try Overlapping. Why does the boundary never settle?
  • Set a huge or tiny learning rate. What changes, and what doesn't? (Hint: for sign with zero starting weights, η only rescales w.)
  • Start from your own hand-picked weights and see how many updates training needs.