Least squares

Gist

The method for finding the best fit line in Linear regression

Calculus-derived

Imagine the simplest case:

Yi=b0+b1Xi,

and let us define the residuals (ri) as:

ri=Yi(b0+b1Xi).

The sum of squared errors is then:

SSE=i=1N(ri)2

If we want to minimize the SSE, we should then find the derivative in respect to b0 and b1:

SSEb0=2(i=1NYii=1Nb0i=1Nb1Xi)SSEb1=2(i=1NYiXii=1Nb0Xi+i=1Nb1Xi2)

And if you set it to 0 and solve for b0:

b0=i=1NYiNi=1Nb1Xi)N=y¯b1X¯

and

Linear algebra- derived

If we look at Multiple regression regression in matrix form

References

  1. https://thepalindrome.org/p/the-anatomy-of-the-least-squares
  2. http://spia.uga.edu/faculty_pages/mlynch/teaching/ols/OLSDerivation.pdf