Using least squares regression for line of best fit

2k Views Asked by At

Use the least square approximation to find the closest line (the line of "Best Fit") to the points:

$$(-6,-1), \quad (-2,2), \quad (1,1), \quad (7,6)$$

I'm attempting to use the least squares approximation formulation that is as follows:

$$A^TAx = A^Tb$$

However, I'm confused because I'm given four vectors. Does that mean I can use the first three vectors $(-6,-1),(-2,2),(1,1)$ to create my matrix A, and then use the last vector $(7,6)$ for the "$b$" value? I understand the process is very straight forward once proper substitution has been done, but I tried the method I described above and got the wrong answer.Thank you guys.

1

There are 1 best solutions below

1
On

You are looking for an equation $y=mx+c$. Ideally it would pass through all of the given points: that is, you would have $-6m+c = -1$, and similarly for other points. This is a set of four equations with two unknowns $m,c$. Its matrix representation is $$ \begin{pmatrix} -6 & 1\\ -2 & 1 \\ 1 & 1 \\ 7 & 1 \end{pmatrix} \begin{pmatrix} m \\ c \end{pmatrix} = \begin{pmatrix} -1 \\ 2 \\ 1 \\6 \end{pmatrix} $$ These are $A$ and $b$ you are looking for. Typically, the system $Ax=b$ has no solutions (there is no line through all the points); this is why we solve $A^TAx=A^Tb$ instead, obtaining $x$ that minimizes the residual $\|Ax-b\|^2$.