The Perceptron

easy
Unit 3 · Classification I0/3 to milestone

The perceptron (1958) is the ancestor of every neural network. For labels y∈{−1,+1}y \in \{-1, +1\}, it predicts sign(w⋅x+b)\text{sign}(w \cdot x + b), and for each misclassified example it updates w←w+η y xw \leftarrow w + \eta\, y\, x and b←b+η yb \leftarrow b + \eta\, y.

Implement train_perceptron(X, y, lr=1.0, epochs=100): start from zeros, loop over examples in order each epoch, and treat w⋅x+b=0w \cdot x + b = 0 as a mistake. Stop early after an epoch with no mistakes. Return (w, b, mistakes_per_epoch).

Also implement predict(X, w, b), returning ±1 (0 maps to +1).

#classification#linear-models#history2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
The Perceptron · TechGradify