How can a model decide whether a sentence is happy or sad, or whether an email is spam? A perceptron learns a line that separates two labeled classes. It combines feature values with weights and a bias, then predicts one class when the score is at least zero and the other when it is negative. section 5.0 section 5.6
The perceptron algorithm improves its classifier through a repeating procedure:
- Start with a random line, represented by weights and a bias. section 5.3
- Choose a labeled point and calculate its prediction. section 5.4
- Leave the classifier unchanged when the point is correct; otherwise, move the line slightly toward that point. section 5.3
- Repeat the update, often one randomly selected point at a time, while tracking mean perceptron error. section 5.3 section 5.4
Happy or sad aliens
Use two features—how often an alien says “aack” and “beep”—with labels 1 for happy and 0 for sad. A from-scratch Python implementation computes score = features · weights + bias, applies a step function, updates misclassified examples with a learning rate, and plots the resulting line and error. On the supplied dataset, the learned classifier classifies every point correctly. section 5.4
Figure 5.20 Case 1 (left): A point that is correctly classified tells the line to stay where it is. Case 2 (right): A point that is misclassified tells the line to move closer toward it.
Use the geometric figure to see the key rule: correct points leave the line still, while misclassified points move it closer. section 5.3
A perceptron works best when classes can be separated by a line or hyperplane; with inseparable classes, it searches for the best separation it can find rather than a perfect one. Try building models for patient diagnosis, AND, and OR, then show why XOR cannot be modeled by one perceptron. section 5.6 section 5.7
