The perceptron
The original learning machine: a linear threshold unit that updates only when it makes a mistake.
Animated explanation
The idea
The perceptron predicts if and otherwise. Its learning rule is almost childishly simple: go through the examples; whenever one is misclassified, add it to the weights (for a positive) or subtract it (for a negative). Correct predictions change nothing.
Each update tilts the boundary towards classifying that point correctly. If some line separates the classes perfectly, the perceptron is guaranteed to find one in a finite number of updates. If no such line exists, it never settles. That limitation, and the fix (multiple layers), is the origin story of neural networks.
The convergence theorem
Suppose a unit vector separates the data with margin (every ) and every . Then the perceptron makes at most mistakes, regardless of the dimension or the order of the data. Each update increases by at least while grows by at most ; both bounds together cap the number of updates.
Limits and fixes
- On non-separable data it cycles forever. The pocket algorithm keeps the best weights seen; the averaged perceptron averages all weight vectors and generalises much better.
- It finds a separating line, not the best one. The SVM picks the line with the largest margin.
- One layer cannot represent XOR. Two layers with smooth activations can: the multi-layer perceptron.
The algorithm, step by step
- 1Encode labels as ; set , .
- 2For each epoch, visit the examples (shuffled).
- 3If : , .
- 4Stop after an epoch with no mistakes (or after a maximum number of epochs).
The maths
Prediction
Update on a mistake
Mistake bound
Strengths and weaknesses
Strengths
- Extremely simple and fast; online (one example at a time)
- Guaranteed to converge on separable data
- Historically the building block of neural networks
Weaknesses
- Never converges on non-separable data
- No probabilities; arbitrary separating line (no margin)
- Linear boundaries only
Reach for it when…
Check your understanding
Lambdian Lab
Train a perceptron and count its mistakes
Labels are ±1.
- fit_perceptron(X, y, epochs): cycle through the data in order; return (w, b, mistakes) where mistakes is the total number of updates. Stop early after a clean epoch.
- predict(X, w, b) → ±1 (treat a score of exactly 0 as −1).
- On XOR the perceptron cannot reach 100% accuracy: show it.