Perceptron, Adaline, logistic regression
Last updated
Three single neurons from three different decades: Rosenblatt's perceptron, Widrow and Hoff's Adaline, and logistic regression from Stage 3. They look different on paper, but they share almost everything: the same weighted sum, the same straight boundary, even the same update rule. What differs is one box, the activation, and the loss that comes with it. This lesson lines them up, shows what each one is really punished for, and meets them in scikit-learn.
By the end of this lesson you can
- Write all three neurons as one weighted sum, one activation and one update rule
- Name each one's activation (step, identity, sigmoid) and loss
- Read the three losses as curves of the margin, and say what each one rewards
- Train all three with scikit-learn's Perceptron, SGDClassifier and LogisticRegression
Same weighted sum, different output and loss
All three neurons start the same way: a weighted sum of the inputs plus a bias,
and all three draw the same kind of boundary, the straight line (or hyperplane) where crosses a threshold. They differ in what they do with while learning.
Write the labels as or for a moment (lesson 3.9's way), and call the number each neuron learns from its output. Then all three use exactly the same update:
The perceptron's output is the step of : 0 or 1. Adaline's is itself. Logistic regression's is the sigmoid , a probability (lesson 3.9). That's all:
Perceptron: the output used for learning is step(z), and it predicts with that output. With a step, y − output is 0 when it's right, so it only learns from mistakes, always by the same amount. Only the two pink boxes change.
For the perceptron, this is lesson 5.2's rule in 0-and-1 form: is 0 when it's right and when it's wrong. For Adaline, it's lesson 5.4's rule. And for logistic regression, it's stochastic gradient descent on cross-entropy, because lesson 3.10 found that cross-entropy's gradient with respect to is : the same "output minus label", with a sigmoid output. Each rule is a step down its own loss.
Step, identity, sigmoid
The three activations, and what each does to learning:
| Neuron | Output used for learning | Loss | Learns from |
|---|---|---|---|
| Perceptron (1958) | step: 0 or 1 | the perceptron criterion | mistakes only, always by the same amount |
| Adaline (1960) | identity: | squared error | every example, in proportion to its error |
| Logistic regression | sigmoid: | cross-entropy | every example, most from confident mistakes |
The step has a problem for learning: its slope is 0 everywhere except at the jump, where it has none. So the perceptron can't do gradient descent on its own output; its rule is a special trick that works only for one layer. Adaline avoids the problem by learning from , which has a slope. The sigmoid is a smooth step: shaped like a step, so its output means "how sure is it this is class 1?", but with a slope everywhere. That's why sigmoid-like activations made it possible, in the 1980s, to train networks of many layers (Stage 6).
What each one optimises
With labels and again, every loss can be written in terms of one number, the margin of an example, : positive when it's on the correct side, the more so the further it is, and negative when it's on the wrong side. Then (lesson 5.4's squared error becomes because ):
- what we really care about, mistakes: 1 if , else 0;
- the perceptron: ;
- Adaline: ;
- logistic regression: , cross-entropy in bits (lesson 1.11).
Read the curves from left (badly wrong) to right (comfortably right):
- Mistakes can't be learned from directly: the curve is flat everywhere, with a jump, so its gradient says nothing. The other three are smooth stand-ins, called surrogate losses.
- The perceptron's loss is 0 for every correct example, however close to the line. So it stops at the first line with no mistakes, with no pull to move away from the nearest points (lesson 5.2).
- Adaline's is smallest at and rises again beyond it. An example that's very right is punished for overshooting, which can drag the line towards it (lesson 5.4's weakness).
- Logistic regression's keeps falling as grows, but flattens out: a very right example costs almost nothing, a near one costs a little, and a mistake costs a lot. It never rewards being too right, and never stops caring about the nearest points.
The SVM (lesson 4.7) belongs in the same family: its hinge loss, , is the perceptron's shifted to demand a margin of 1.
In scikit-learn
All three are in scikit-learn. Perceptron is lesson 5.2's rule. SGDClassifier trains a linear model by stochastic gradient descent with a loss you choose: loss="squared_error" is Adaline, loss="hinge" a linear SVM, loss="log_loss" logistic regression, and loss="perceptron" the perceptron. Here, LogisticRegression stands in for logistic regression. On Adelie against Chinstrap bills, which overlap, each in a pipeline with scaling and scored on the same five folds (lesson 4.14):
The perceptron: 94.9%, and the most variable, from 88.4% to 97.7%. Adaline and logistic regression: 96.8% each. On overlapping classes the perceptron's final line depends on where it happened to stop, which costs it on some folds; the other two settle at the bottom of a smooth loss.
In practice, of the three, use logistic regression: it gives probabilities as well as classes, settles on overlapping data, and isn't dragged by far-off points. The perceptron and Adaline matter today for what they started: one learning rule, and one unit, that Stage 6 will stack into networks.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- scikit-learn: Stochastic Gradient Descent: SGDClassifier and its losses: hinge, log_loss, perceptron, squared_error
- scikit-learn: Linear models, Perceptron: the perceptron as SGD with the perceptron loss
- Cox, The regression analysis of binary sequences, Journal of the Royal Statistical Society B 20(2), 1958: logistic regression, the same year as the perceptron
- Widrow and Lehr, 30 years of adaptive neural networks: perceptron, Madaline, and backpropagation, Proceedings of the IEEE 78(9), 1990: the perceptron and Adaline rules side by side