Naive Bayes reached a linear classifier indirectly, by modelling each class and comparing them. The perceptron, proposed by Frank Rosenblatt in 1958, goes straight for the boundary. Its learning rule fits in one line, and it comes with one of the first and most elegant guarantees in machine learning.
A linear classifier
The perceptron predicts with a hyperplane through the origin:
(An intercept is handled, as before, by appending a constant feature 1.) The vector is perpendicular to the boundary and points towards the positive side.
A point is classified correctly exactly when : the label and the score have the same sign. That product, , will matter throughout the rest of the course; it is called the margin of the point (positive means correct, and larger means more comfortably correct).
The learning rule
Start with . Repeatedly go through the training points; whenever a point is misclassified (), update
Stop when a full pass makes no mistakes.
Why does this help? After the update, the same point's margin becomes
larger by . The update rotates towards a misclassified positive point (or away from a misclassified negative one). It may break other points that were correct, so it is not obvious that the process ever ends. It does, if the data allows it.
Linearly separable data
The data is linearly separable if some classifies every training point correctly. Then we can scale to unit length and ask how comfortably it separates the data. Define the margin of the data with respect to ,
the distance from the boundary to the closest point, and the radius of the data,
The convergence theorem
If the data is linearly separable with margin and radius , the perceptron makes at most mistakes, and then classifies all the training points correctly.
The proof tracks two quantities after mistakes, being the weight vector at that point.
1. gains alignment with steadily. Each mistake on point adds , so
since every point has margin at least . Starting from , after mistakes .
2. grows slowly in length.
because the middle term is (it was a mistake) and . So .
Combine them. Since has unit length, the Cauchy–Schwarz inequality gives . So
The alignment grows in proportion to , but the length only like ; they cannot keep that up forever, so the mistakes must stop. The bound depends on neither the number of points nor the dimension, only on how wide the gap between the classes is relative to the size of the data. A wide margin means few mistakes. That idea, that the margin governs how hard a problem is, leads directly to support vector machines in Module 10.
Limits of the perceptron
- Non-separable data. If no hyperplane separates the classes, some point is always misclassified, the updates never stop, and the final depends on where you happen to stop. Variants fix this: the pocket algorithm keeps the best seen so far, and the averaged perceptron predicts with the average of all the 's, which is far more stable.
- Any separator will do. On separable data the perceptron stops at the first boundary that works, which may pass very close to some points. It has no preference for a boundary in the middle of the gap, so its predictions on new points near the classes can be fragile.
- Only linear boundaries. Rosenblatt's critics, Minsky and Papert, emphasised in 1969 that a single perceptron cannot represent XOR. Kernels (the perceptron's updates only involve dot products, so it can be kernelised) and multi-layer networks (Module 11) both remove that limit.
The perceptron can also be seen as stochastic gradient descent on a particular loss, the perceptron loss , which is zero for every correctly classified point however close to the boundary. Module 11 compares it with the losses of the other classifiers.