Contents
06Why not squared error for classification?
6.1The vanishing gradient
Nothing stops us from training a sigmoid classifier with squared error on the probability, \ell=(p-y)^2 with p=\sigma(z). The chain rule gives
Compare with p-y for cross-entropy (8). The extra factor p(1-p) is tiny whenever the sigmoid is saturated, including when the model is confidently wrong. Take a true label 1 and logit z=-5: then p=0.0067. Cross-entropy pulls with p-y=-0.993; squared error with 2(p-y)\,p(1-p)=-0.0132, about 75 times weaker (Figure 4b). The model learns slowest exactly when it is most wrong. With cross-entropy, the loss saturates only when the answer is already right (Goodfellow et al., 2016, §6.2.2.2).
6.2Not convex
Squared error on a sigmoid also loses convexity. For y=1, L(z)=(\sigma(z)-1)^2 has L'(z)=-2\sigma(1-\sigma)^2 and
which is negative when \sigma<1/3, that is for z<-\log2\approx-0.69: the loss curves downwards and flattens out on the wrong side. Cross-entropy, L(z)=-\log\sigma(z)=\log(1+e^{-z}), has L''(z)=\sigma(1-\sigma)>0 everywhere, so logistic regression has a single minimum.
6.3What happened in practice
Neural networks of the 1980s and 1990s were commonly trained with mean squared error even for classification. The switch to cross-entropy, a maximum-likelihood loss, was one of the main algorithmic changes that greatly improved networks with sigmoid and softmax outputs (Goodfellow et al., 2016, §6.6). Squared error on probabilities survives as an evaluation score (the Brier score), where its gentleness is harmless.
Pause and think. Squared error and cross-entropy both have their minimum at p=y. Why does it matter which one we train with?
Show the answer
Because training follows the gradient, not just the location of the minimum. The two losses have the same target but very different slopes on the way: squared error’s gradient nearly vanishes for confident mistakes, and it is not convex, so gradient descent can stall far from the minimum.