AI Hints
Statistics & Math for ML · Lesson 69 of 138

Correlation Is Not Causation

Hidden causes.

⏱ 2 min read▶ Video at 1:21:06🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

Ice cream sales and drownings are strongly correlated. Does ice cream cause drowning? Of course not. Hot weather makes people buy ice cream, and also makes people swim. Temperature is a hidden cause, called a confounder.

Correlation Is Not Causation
From the video: Correlation Is Not Causation
  • Ice cream and drownings
  • Correlated, not causal
  • Hot weather drives both

A confounder in action

We simulate ten years of days. Temperature drives both ice cream sales and swimming accidents, but ice cream has no effect on accidents at all. Run it. A strong correlation anyway. But if we look only at days with similar temperatures, the correlation almost disappears.

confounder.pypython
import numpy as np

rng = np.random.default_rng(0)
temp = rng.uniform(5, 35, 3650)
ice_cream = 20 * temp + rng.normal(0, 60, 3650)
accidents = 0.3 * temp + rng.normal(0, 2, 3650)

print("overall r:", np.corrcoef(ice_cream, accidents)[0, 1].round(2))
warm = (temp > 25) & (temp < 28)
print("similar days r:", np.corrcoef(ice_cream[warm], accidents[warm])[0, 1].round(2))
Output
overall r: 0.75
similar days r: 0.0

How to find causes

The gold standard is a randomized experiment, like an A/B test. Random assignment breaks the link with confounders. When you can't experiment, you can control for known confounders, by comparing similar groups. In machine learning, a model can predict well from correlations, but that doesn't mean changing a feature will change the outcome.

keyvalue
Confoundera hidden common cause
Experimentsrandomize to find causes
Observational datacontrol for confounders
MLprediction isn't causation

Summary

Correlation doesn't prove causation. Look for confounders, and use experiments when you can. Next, drawing the best straight line through data.

Key takeaways
  • Look for confounders
  • Randomize when possible
  • Predict ≠ cause
Next up: Simple Linear Regression — the best line