## Saturday, January 6, 2018

Published 12:28 PM by with 0 comment

# What Value Minimizes The Sum Of Squared Errors For A Group Of Numbers?

I noticed this result at work one day and it caught me off guard...
Start with the definition of the sum of squared errors:

To find the value of b that minimizes this, we take the derivative and set the result to 0:

Noting that b has no dependence on i, the sum on the right reduces to n*b and we have:

That last equation is the mean of y. I thought this was kind of cool even though it's really obvious when doing the math.

I noted at the beginning that I noticed this at work. Specifically, it was doing a linear fit where the slope ended up being very close zero. If we take the derivation of that (copied from wikipedia):

and the slope ends up being zero, you get the same equations I walked through above. A simple plot showing it with numbers:

The best fit runs straight through the mean. Neat.