Three ways to learn a line
Every review becomes a vector of 13,000 zeros and ones — one per word in the training vocabulary. A linear classifier scores it as θ·x + θ₀ and predicts the sign. The three algorithms differ only in how they move θ:
- Perceptron — on a mistake,
θ ← θ + y·x. Simple, converges if the data is separable, and it is: 99 % training accuracy but only ~80 % on new reviews. - Average perceptron — same updates, but the answer is the average of every θ seen during training. Cheap insurance against the last few updates overfitting.
- Pegasos — stochastic sub-gradient descent on the SVM objective: shrink θ by
(1 − ηλ)every step and addη·y·xwhen the margin is below 1, withη = 1/√t. The regulariser λ trades training accuracy for margin.
Because the model is linear, it is completely explainable: the Analyze tab colours every word by its weight, and the Words tab lists the biggest ones.