TITLE: Why get the sum of squares instead of the sum of absolute values?
QUESTION [31 upvotes]: I'm self-studying machine learning and getting into the basics of linear regression models. From what I understand so far, a good regression model minimizes the sum of the squared differences between predicted values $h(x)$ and actual values $y$.
Something like the following:
$$\sum_{i=1}^m (h(x_i)-y_i)^2$$
Why do we square the differences? On one hand, it seems squaring them will allow us to get a positive number when the expected value is less than the actual value.
But why can't this just be accounted for by taking the sum of the absolute values?
Like so:
$$\sum_{i=1}^m |h(x_i)-y_i|$$

REPLY [6 votes]: I study regression, and I used to wonder this very question myself.
Now I've come to the conclusion it's because of the geometry and linear algebra behind regression. Suppose we collect data on $n$ observations and to run a regression. When we minimize the sum of squared residuals, the way we do this (using Ordinary Least suares) is via projection matrices. We project a vector of explanatory variables (the "y" variables) onto a hyperplane of the explained variables (the "regressors" or "x" variables). By using projections, we are able to find the "closest" vector in the hyperplane (call it $\mathbf{x}\hat{\mathbf{\beta}}$, making the "error" vector of residuals $\hat{\mathbf{u}}$ as small as possible.
This is the key: when we choose $\hat{\mathbf{\beta}}$ to make the vector of residuals as "small" as possible, this means we are minimizing its Euclidean length:
\begin{align}
min |\mathbf{y}-\mathbf{x\beta}| &= min |\hat{\mathbf{u}}| \\
&= min \sqrt{\hat{\mathbf{u}}^\top\hat{\mathbf{u}}} \\
&=min \sqrt{\hat{u}_+\hat{u}_2+\cdots+\hat{u}_n}
\end{align}
And this is where the sum of SQUARES comes in. It's actually a geometric result.