Correlation vs Causation
When two things move together, one might cause the other, or a hidden third factor might be driving both. ML optimizes correlation; intervention requires causation.
Why Does This Exist?
Your model can predict well and still recommend the wrong action. That gap is why this distinction matters.
Take eight beach days. Shark sightings and ice cream tubs move together with correlation 0.96, so a model that predicts tubs from sharks looks brilliant offline. Ban swimming and tubs will not budge, because heat drives both. You called the future right and still picked a lever that does nothing.
Basics first, briefly: correlation is the linear co-movement number between minus one and one, defined in correlation coefficient. Causation is what happens when you force a change. This page shows how the first number can hit 0.96 with zero push from sharks, how to spot the hidden driver, and what to do instead. Causal graphs give you the arrow map for choosing adjustments, confounding and colliders zooms into the two junctions you must treat in opposite ways, and randomized experiments show the fix when you can randomize.
Think of It Like This
The rooster that takes credit for dawn
You hear the rooster crow, then the sun rises. Every dawn follows a crow, so the crow predicts sunrise perfectly.
The rooster is shark sightings, sunrise is ice cream sales, and Earth spin is heat. Spin lights the sky and wakes the bird, just as heat fills the beach with swimmers and buyers. Mute the bird and dawn still comes. Close the beach and tubs still sell on hot days.
Where it stops: the farm story sounds exact, while real beach days wiggle by a tub or two inside the same heat. That wiggle is why you must compute the within group link instead of trusting the pooled picture.
How It Actually Works
Call shark sightings , meaning the count you observe but do not control. Call ice cream tubs , meaning the outcome you want to move. Call temperature , meaning the background cause that comes first and pushes both. Correlation measures linear co-movement from the data you saw. Causation measures what forcing would do.
What correlation measures
Pearson correlation rescales covariance by both spreads:
Here means the average product of deviations from the means, means the standard deviation of , and means the standard deviation of . The result always sits between minus one and one. Plus one is a perfect rising line, minus one a perfect falling line, zero no straight line link. It says nothing about what would happen if you intervened.
What causation adds
Seeing is , meaning the share of among days where happened to equal . Doing is , meaning the share if you forced to everywhere. A confounder fork keeps those two apart: and move together through even when does nothing to . That open backdoor path is the whole trap.
You close it by stratifying on , meaning compare days within the same heat, then average. If the within group link is flat while the pooled link is steep, did the talking. When no measured can close every backdoor, you need a new design such as A/B testing or the counterfactual framing in potential outcomes.
Worked example: eight beach days from 0.96 to 0.00
Take eight days as a teaching set, not a trial. Cool days run near 20C, hot days near 30C:
- Cool : ,
- Hot : ,
- Pooled , pooled
Pooled means are sharks and tubs. Sum of squared deviations are for and for , with cross sum :
A naive line through the pool has slope tubs per shark. It reads as if each extra shark brings three tubs.
Now hold heat fixed. Cool means are sharks and tubs. Hot means are sharks and tubs, so the strata gap is tubs. Inside cool days the cross sum is on sums of squares and , so . Hot days match exactly, cross sum , so . Sharks explain none of the two tub wiggle inside a heat level. The diagram draws these same numbers: two clouds, one steep pooled tilt, two flat within group lines.
Code
The point is the check: pooled correlation looks strong, each heat slice is flat, and the strata gap carries the full 14 tubs.
X: list[float] = [1, 1, 2, 2, 5, 5, 6, 6]Y: list[float] = [10, 12, 12, 10, 24, 26, 26, 24]
def pearson(a: list[float], b: list[float]) -> float: ma = sum(a) / len(a) mb = sum(b) / len(b) sxy = sum((x - ma) * (y - mb) for x, y in zip(a, b)) sxx = sum((x - ma) ** 2 for x in a) syy = sum((y - mb) ** 2 for y in b) return sxy / (sxx * syy) ** 0.5
print(pearson(X, Y)) # -> 0.9603920767980495print(pearson(X[:4], Y[:4])) # -> 0.0print(sum(Y[4:]) / 4 - sum(Y[:4]) / 4) # -> 14.0The printout matches the hand computation: pooled 0.96, cool slice 0.0, strata gap 14.0.
Watch Out For
Shipping the proxy as the lever
Symptom: offline error looks great with sharks as a feature, the team closes the beach or bids on shark alerts, and tub sales do not move. Fix: demand an intervention test before you ship the lever, such as randomized experiments or A/B testing. Prediction needs correlation, action needs causation.
Adjusting for a downstream variable
Symptom: the estimate flips or blows up after you add a variable that the treatment or outcome causes, like beach photos that crowds and sales both produce. Fix: adjust only for pre treatment causes picked from a graph, never for consequences. Causal graphs and confounding and colliders show which node stays in and which stays out.
The Quick Version
- Correlation 0.96 between sharks and tubs across eight beach days shrinks to 0.00 inside each temperature group.
- A confounder fork makes two variables move together through heat with no push between them.
- Seeing predicts the future while doing predicts the effect of an action, and only the second guides a decision.
- Cool days average 11 tubs and hot days average 25 tubs, so the full 14 tub gap traces to heat rather than sharks.
- A naive slope of 3.29 tubs per shark looks actionable offline and goes flat once heat is held fixed, which is why levers need experiments.