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 and predictions , define residuals . Then
The common regression loss is the squared norm, up to a constant, rather than the norm itself. Without other objective terms, minimizing MSE, the sum of squared errors, RMSE, or 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
with common fixed variance , conditional on the inputs. The negative log likelihood is
The first term does not depend on , so maximum likelihood selects the parameters minimizing squared error. We optimize over , with the observed 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 instead have density proportional to , 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 has finite second moment and , then
Thus the expected squared error is minimized uniquely at the mean. Applying the same argument conditionally on gives the conditional mean as the unrestricted optimal prediction.
For absolute error, assuming a finite first moment, a minimizer is any median: a value with
For a distribution with a continuous density, differentiating with respect to gives , so a minimum occurs where . The median condition above also handles atoms and nonunique medians.
For the sample , the squared-error constant prediction is , while the absolute-error prediction is . The distinction reflects the loss we chose, rather than an algebraic superiority of one answer.
Robustness and optimization
A residual of magnitude contributes to squared loss but to absolute loss. For squared loss, the derivative with respect to the residual is ; for absolute loss away from zero, it is . 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 , neither loss guarantees a convex optimization problem in .
What “best” means in linear regression
For , assume has full column rank, , and . Ordinary least squares is the best linear unbiased estimator of , 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.