fit a line $ax$ to function $\sin(\pi x)$ from $x=-1$ to $1$, that produces the minimal mean square error.

48 Views Asked by At

I want to fit a line $$ax$$ to function $$\sin(\pi x)$$ from $x=-1$ to $1$, that produces the minimal mean square error.

It should be $\int_{-1}^1 (\sin(\pi x)-a x)^2 \, dx$. Then I take derivative with respect to $a$, and set it to $0$. However, I found the answer of $a$ to be $3/\pi$, which is not $1.43$.

But plot the curve, I can clearly see that the answer should be $1.43.$ What is going on?enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Possibly what's going on is that your intuition is not taking into account the asymmetry between the $x$- and $y$-directions, and maybe you don't understand why there ought to be such asymmetry.

Consider this scatterplot: $\{(0,0), (0,1), (1,0)\}$

Fit a least-squares line $y=a + bx$. Choose $a$ and $b$ to minimize $$\sum_{k=1}^3 (y_k -(a+bx_k))^2.$$ It will go straight through the point $(1,0)$ and half-way between $(0,0)$ and $(0,1)$. Draw the picture and see if you can figure out why that is.

But now instead, fit a line $x=e+fy$ where $e$ and $f$ are chosen to minimize $$ \sum_{k=1}^3 (x_k -(e+f y_k))^2. $$ This line will go straight through $(0,1)$ and half-way between $(0,0)$ and $(1,0)$. Again draw the picture and see why it must work that way.

They're not the same line.

If you had symmetry between $x$ and $y$, you'd get a line straight through $(0,0)$ and half-way between $(1,0)$ and $(0,1)$. I wonder if your intuition is telling you to expect that line.