Prove minimum argument of square error function is equal to expected value Consider a probability density function $f(x)$ defined over the interval $[a,b]$ where $-\infty<a<b<\infty$.
The square error function is defined as $J(y)=\int_a^b (x-y)^2f(x)dx$.
The argument $y$ that outputs the minimum $J(y)$ is defined as $y_1$.
I have to prove that $y_1$ is equal to $E(X)$. 
I have tried doing the problem by myself but I have no idea where to start from. It makes sense that for a square error function to have the least error, it should be centered around the mean. However, due to my lack of math skills, I just couldn't find my way into this proof. Could I get some guidance please?
 A: $J(y)=∫_a^b(x−y)^2f(x)dx = E(X^2) -2yE(X) + y^2$
Deferential is $2y - 2E(x)$. 
Let it equal to zero you get $Y=E(X)$.
By secondary deferential, = 2 >0, you get result.  
A: We can solve this using ordinary calculus techniques.  Applying Leibniz integral rule you have:
$$\begin{equation} \begin{aligned}
J'(y) 
&= \frac{d}{dy} \int \limits_a^b (x-y)^2 f(x) dx \\[6pt]
&= \int \limits_a^b \frac{\partial}{\partial y} (x-y)^2 f(x) dx \\[6pt]
&= - 2 \int \limits_a^b (x-y) f(x) dx \\[6pt]
&= - 2 \Bigg[ \int \limits_a^b x f(x) dx - y \int \limits_a^b f(x) dx \Bigg] \\[6pt]
&= - 2 \Big[ \mathbb{E}(X) - y \Big], \\[12pt]
J''(y) 
&= - 2 \frac{d}{dy} \Big[ \mathbb{E}(X) - y \Big] = 2. \\[6pt]
\end{aligned} \end{equation}$$
We can see from the second-derivative that $J$ is a strictly convex function, so it has a unique critical point that is the global minimising value.  This point is given by solving the critical point equation:
$$0 = J'(\hat{y}) = - 2 \Big[ \mathbb{E}(X) - \hat{y} \Big] \quad \quad \implies \quad \quad \hat{y} = \mathbb{E}(X).$$
