Conditional Expectation: Optimality, Proof, and Applications
Which function of the features minimizes mean squared error (MSE)? If the outcome has a finite second moment, the answer is , its conditional mean. We prove this by separating prediction error into the outcome's variation around that mean and the predictor's deviation from it. We then use the same reasoning to explain how estimating a predictor from data adds bias and variance.
1. Theorem: Optimality of the Conditional Expectation
Statement:
Let on , with . Write for the marginal distribution of and for a conditional distribution of .
Throughout the proof, means . Conditioning on means keeping the input fixed and averaging over . An outer expectation also averages over . Thus is a random variable, while is its value at a fixed input.
We compare measurable, fixed predictors satisfying . Their MSE loss is
Then a minimizing predictor is
The minimizer is unique up to equality almost surely, not necessarily at every possible input. More precisely,
2. Proof of the Theorem
Error Decomposition
To compare a predictor with the conditional mean, add and subtract that mean. For any admissible function in the class above,
Squaring both sides gives:
Taking Expectations and Eliminating the Cross Term
Squaring introduces a cross term. Taking expectations gives:
By the linearity of conditional expectation,
The other factor is a function of . Conditioning on and applying the tower property therefore removes the cross term:
The cross term vanishes because the residual has conditional mean zero. The expected squared error therefore separates into:
Minimization
The term is independent of and represents the irreducible error given . The second term is nonnegative and equals zero if and only if almost surely. Therefore, the unique minimizer in is:
3. Connection to the Bias–Variance Tradeoff
The proof identifies the best prediction target. We next ask how estimating that target from data contributes to prediction error. Let be random training data independent of a new test pair , and let be the fitted predictor. For independent and identically distributed training pairs from , .
Write and for the conditional mean and variance. Subscripts and below mean that we average over and , respectively. At a fixed input , the joint average is over : the training data and outcome vary, but stays fixed. Assuming the displayed second moments are finite,
Total Expected Error Decomposition
To obtain overall test error, average the pointwise decomposition over the test-input distribution. With and , this gives
Optimality of the Conditional Expectation
If the conditional mean were known, no fitting would be needed:
- Bias:
- Variance:
At a fixed input, does not depend on the training data, so its estimation variance is zero. This does not mean that the outcome itself has zero variance. - Total Error:
This is the minimum possible error achievable, showing that is optimal in the sense.
4. Use Cases and Practical Implications
A. Linear Regression
In linear regression, we restrict the predictor to be linear:
Ordinary least squares (OLS) chooses the coefficient vector that minimizes squared error in the sample. At the population level, the best linear predictor approximates within the chosen linear class. It need not equal the true conditional mean if that mean is not linear.
The Gauss–Markov theorem concerns coefficient estimation rather than prediction over all functions. Under a correctly specified linear mean, a full-rank design, and errors with zero conditional mean and covariance proportional to the identity, OLS has the smallest covariance among linear unbiased estimators of the coefficient vector. This is the best linear unbiased estimator (BLUE) guarantee; it does not make OLS the best predictor among all functions.
B. Deep Learning and Transformer Models
For a continuous response , a neural network trained with squared error uses the sample objective
Under squared loss, the unrestricted population target is . A fitted network need not equal this target: the model class, data, regularization, and optimization determine how well it approximates the conditional mean.
- Uncertainty Modeling:
A conditional mean does not specify a full predictive distribution. One possible simulation model adds a sampled residual: where is the predicted conditional mean. Conditional on the fitted model and a pool of residuals , drawing samples uniformly from that empirical distribution; denotes a point mass at . Pooling residuals across histories assumes that the pooled distribution is appropriate at each simulated history. It can miss history-dependent variance or other changes in the error distribution.
C. Counterfactual Outcome Prediction
For a concrete example, G-Transformer uses MSE to fit continuous covariate predictions and samples residuals from a holdout set when simulating trajectories. The conditional-mean target explains the role of squared error in that procedure. Residual sampling adds a distributional modeling step; it is not a consequence of MSE optimality. Moreover, interpreting the simulated trajectories causally requires the paper's identification assumptions, including consistency, sequential exchangeability, and positivity.
Conclusion
For square-integrable outcomes, is the unique MSE-minimizing predictor up to almost-sure equality. The proof separates the variation that remains around this target from the error of a candidate predictor. Once the target must be estimated from data, the bias–variance decomposition separates squared bias and estimation variance from irreducible error. Keeping the target and its fitted approximation distinct is essential when interpreting either a regression model or a neural network.
References and Further Reading
- Cosma Shalizi, Linear Regression as Prediction, for conditional-mean prediction and linear approximation.
- Hong Xiong and colleagues, G-Transformer: Counterfactual Outcome Prediction under Dynamic and Time-varying Treatment Regimes, for the trajectory-simulation example.
