Why Use Squared Error Rather Than Absolute Error?

A probabilistic and optimization-based explanation of why squared error is so common in loss functions.

Squared error and absolute error answer different estimation questions. Squared error emphasizes large residuals and targets a conditional mean; absolute error is less sensitive to large response errors and targets a conditional median. Neither is universally the correct loss.

First distinguish the quantities

For observations (xi,yi)(x_i,y_i) and predictions fθ(xi)f_\theta(x_i), define residuals ri=yifθ(xi)r_i=y_i-f_\theta(x_i). Then

r1=i=1Nri,r2=i=1Nri2,MSE=1Nr22.\|r\|_1=\sum_{i=1}^{N}|r_i|,\qquad \|r\|_2=\sqrt{\sum_{i=1}^{N}r_i^2},\qquad \mathrm{MSE}=\frac1N\|r\|_2^2.

The common regression loss is the squared L2L^2 norm, up to a constant, rather than the norm itself. Without other objective terms, minimizing MSE, the sum of squared errors, RMSE, or r2\|r\|_2 gives the same set of minimizers. Their derivatives differ, and replacing one by another inside a regularized objective need not preserve the minimizer.

A likelihood justification

Suppose the observation model is

yi=fθ(xi)+εi,εiindN(0,σ2),y_i=f_\theta(x_i)+\varepsilon_i, \qquad\varepsilon_i\overset{\mathrm{ind}}\sim\mathcal N(0,\sigma^2),

with common fixed variance σ2>0\sigma^2>0, conditional on the inputs. The negative log likelihood is

logp(y1,,yNx1,,xN,θ)=N2log(2πσ2)+12σ2i=1Nri2.-\log p(y_1,\ldots,y_N\mid x_1,\ldots,x_N,\theta) =\frac N2\log(2\pi\sigma^2) +\frac1{2\sigma^2}\sum_{i=1}^{N}r_i^2.

The first term does not depend on θ\theta, so maximum likelihood selects the parameters minimizing squared error. We optimize over θ\theta, with the observed yiy_i held fixed. Likelihood is the data density regarded as a function of the parameters, not a probability distribution over those parameters. Ng's CS229 notes give this derivation.

Independent Laplace errors with fixed scale b>0b>0 instead have density proportional to eε/be^{-|\varepsilon|/b}, producing an absolute-error objective. Neither noise assumption is automatic. In particular, the central limit theorem does not establish that every measurement or prediction error is Gaussian.

Mean versus median

There is also a justification that does not assume Gaussian noise. If YY has finite second moment and μ=E[Y]\mu=\mathbb E[Y], then

E[(Ya)2]=Var(Y)+(aμ)2.\mathbb E[(Y-a)^2]=\operatorname{Var}(Y)+(a-\mu)^2.

Thus the expected squared error is minimized uniquely at the mean. Applying the same argument conditionally on X=xX=x gives the conditional mean as the unrestricted optimal prediction.

For absolute error, assuming a finite first moment, a minimizer is any median: a value mm with

Pr(Ym)12,Pr(Ym)12.\Pr(Y\le m)\ge\frac12,\qquad\Pr(Y\ge m)\ge\frac12.

For a distribution with a continuous density, differentiating EYa\mathbb E|Y-a| with respect to aa gives 2F(a)12F(a)-1, so a minimum occurs where F(a)=1/2F(a)=1/2. The median condition above also handles atoms and nonunique medians.

For the sample 0,0,100,0,10, the squared-error constant prediction is 10/310/3, while the absolute-error prediction is 00. The distinction reflects the loss we chose, rather than an algebraic superiority of one answer.

Robustness and optimization

A residual of magnitude 1010 contributes 100100 to squared loss but 1010 to absolute loss. For squared loss, the derivative with respect to the residual is 2r2r; for absolute loss away from zero, it is sign(r)\operatorname{sign}(r). This explains why a large response residual exerts more influence under squared loss. Absolute-error regression can still be vulnerable to unusual input points with high leverage; “more robust” is not “immune to outliers.”

Squared loss is smooth and leads to a quadratic objective for linear regression. Absolute loss is convex but nondifferentiable at zero; subgradient methods or linear programming can handle it. With a nonlinear model fθf_\theta, neither loss guarantees a convex optimization problem in θ\theta.

What “best” means in linear regression

For y=Xβ+εy=X\beta+\varepsilon, assume XX has full column rank, E[εX]=0\mathbb E[\varepsilon\mid X]=0, and Cov(εX)=σ2I\operatorname{Cov}(\varepsilon\mid X)=\sigma^2I. Ordinary least squares is the best linear unbiased estimator of β\beta, where “best” means minimum covariance within that class. Gaussian errors are not required for this Gauss–Markov result, and the result does not compare OLS with every biased or nonlinear estimator.

Classification also requires a loss suited to its target. Cross-entropy corresponds to a categorical likelihood, while squared error on predicted probabilities gives the Brier score. It is inaccurate to say that squared loss is inherently invalid for classification.

Choose the loss according to the quantity to predict, the cost of errors, the data assumptions, and the optimization problem. The likelihood derivation is one justification for squared error, not a rule that all errors should be squared.