Textbook :
If we know $X=x$, then our best guess for $Y$ is $E(Y |X=x)$. Now $E(Y |X)$ is a random variable taking the value $E(Y | X = x)$ when $X = x$. So somebody who knows $X$ (whatever it turns out to be) would guess $E(Y | X)$. Their expected squared error is
$$E [(E(Y |X)−Y)^2] =E [E(Y |X)−Y] ^2 +\text{Var} [E(Y |X)−Y ]$$
The first term is $0$ by the tower property . The second term is no larger than $\text{Var}(Y )$ . As a consequence $E(Y | X)$ is a better guess than $E(Y )$ or at least as good.
Question:
The guess is a random variable $E(Y|X)$ and I don't quite understand what it means here.
If we know a specific $x$, then the guess should be $E(Y|x)$ instead of $E(Y|X)$. If not, should the guess be $E(E(Y|X))$, which is $E(Y)$?
Thanks in advance!
There's a lot of ways to approach this, including defining conditional expectations in the measure-theoretic sense, but to keep it simple, $E(Y|X=x)$ is a constant (so a degenerate random variable), whereas $E(Y|X)$ is a random variable in the conventional sense. Intuitively, we want to think of comparing the random variable $Y$ to something that is close to $Y$ given the information we have. One guess could be to use $E[Y]$, which is a constant. However, if we have information about another random variable $X$ (that is not independent of $Y$), we can actually do better, and in some sense, that is exactly what $E[Y|X]$ is defined as. To make things clear, imagine that the random variable $Y$ is defined as $$Y = \alpha X$$ Then $$E[Y] = \alpha E[X]$$ However, $$E[Y|X] = E[\alpha X|X] = \alpha E[X|X] = \alpha X $$ and so $E[Y|X] = Y$ in this example! So we fully recover $Y$ when we take the conditional expectation with respect to $X$ in this case. $Y$ is clearly a random variable, so it should already make sense why we don't want to think of $E[Y|X=x]$ as our best guess of the random variable $Y$, because it would be saying that my best guess is a constant, when I just showed you I can do a lot better.
Happy to be a lot more formal if you'd like, but hopefully this helps with intuition, which seems to be your question.