Relation between linear regression and conditional expectation If we do linear regression we have the following decomposition of the sum of square. I call $y_i,x_i,\hat{y}_i$ the observed variables, the predictors and the linear predictions respectively. Then the residuals are $e_i=y_i-\hat{y}_i$. We also indicate with on overline the mean over all samples. Than:
$$\sum_i (y_i-\overline{y})^2=\sum_i \left(\hat{y}_i-\overline{\hat{y}}\right)^2+\sum_i (e_i-\overline{e})^2 \tag{1}$$
There are other few properties ($\overline{y}=\overline{\hat{y}}$ and $\overline{e}=0$).
A similar formula comes from the theory of conditional expectation. Given two r.v. $X,Y$:
$$Var(Y)=Var(E[Y|X])+E[Var(Y|X)] \tag{2}$$
I see some similarities in these two formulas, if we consider the $\hat{y}_i$ related to $E[Y|X]$.
My question is this. Can the first formula be derived from the second? How deep is their connection (if indeed there is one) ?

Regression models in general model the conditional expectations. It's not an expectation, but a specific form of expectation
$$
E[y|X] = f(X)
$$
where $f$ is the regression function that can be different things: linear function as in linear regression, or many other functional forms, including non-linear as in non-linear regression, regression forests, or neural networks, etc.
It's unclear what kind of special relationship with the law of total variance you are looking to find. The law applies to any conditional variances, so there is nothing special for linear regression here. Additionally, variance is defined in terms of squared deviations, while mean and linear regression both minimize squared error (as many other models) so there are similarities due to using squared deviations.
