Conditional Expectation
Conditional expectation re-takes the average after learning something. A die averages 3.5, but averages 4 once you know the roll was even.
Why Does This Exist?
Models rarely predict in the dark. They predict after seeing features: the expected price given the neighborhood, the expected click given the history. Plain expectation averages over everything; conditional expectation averages after information arrives.
Without it there is no regression theory, no Bayes update, and no filtering. The conditional expectation is the least-squares best predictor given what you know, and every "expected value given features" in ML is one. It extends expectation, variance and covariance to the case where knowledge has arrived.
The one idea you need first
Expectation is a weighted average: for a fair die, . Conditional expectation repeats that average on a smaller set, reweighted to sum to 1 inside it.
Think of It Like This
Re-grading after the class splits
A teacher averages all exam scores: 72. Then the class splits into two rooms and she re-averages inside each room: 68 in one, 78 in the other. Nobody retook the exam; the information changed.
Conditional expectation is the room average. It is still a random object before you know your room, and a plain number after. The tower rule says averaging the room averages, weighted by room size, returns the class average. Where the analogy stops: rooms are fixed, while -algebras can refine continuously as new data streams in.
How It Actually Works
Given information (an event, a variable, or a -algebra), is the unique -measurable variable satisfying for every in . In plain words: it matches on every question can ask, and it asks nothing cannot.
Properties you actually use
- Tower: when . Coarsen in steps or all at once.
- Taking out what is known: if is -measurable, .
- Best predictor: minimizes over -measurable . Regression targets it.
Worked example
Fair die, the face. Plain mean . Learn the event ("even"). Re-average inside: . Learn instead the exact face and the conditional collapses to . Tower check: , , and . The cells recombine to the whole.
Code
import numpy as np
rng = np.random.default_rng(1)rolls = rng.integers(1, 7, size=60000)print(round(float(rolls.mean()), 3)) # -> 3.499print(round(float(rolls[rolls % 2 == 0].mean()), 3)) # -> 4.004Sixty thousand rolls give 3.499 overall and 4.004 on the even subset, against exact 3.5 and 4.
Watch Out For
Treating E[X | Y] as a number before Y is known
is a function of , hence random. People plug in for one and treat the whole object as that number. Then the tower rule looks false and downstream variance math breaks.
Keep the two apart: varies with ; is its value at one point. Take the outer expectation to get back to a number.
Conditioning on zero-probability points with the ratio formula
needs . With continuous features, and the ratio is . Filtering code that subsets to exact floats hits this silently.
Condition on intervals or use densities and the measure-theoretic definition. If the subset has fewer than a dozen rows, widen the window before trusting the average.
The Quick Version
- Conditional expectation is the average after information arrives: same variable, smaller world.
- A fair die averages 3.5 overall and 4 given even, since .
- The tower rule recombines cell averages into the whole average.
- Known factors pull out; the conditional expectation is the least-squares best predictor.
- Before the information is known it is random; after, it is a number.
- Never condition on exact continuous values with the elementary ratio formula.