PROBABILITY & STATISTICS / 7. CORRELATION & COVARIANCE
Correlation & Covariance
How variables move together — and why correlation ≠ causation
EXPLANATION
Covariance measures how two variables change together. Cov(X,Y) = E[(X-μₓ)(Y-μᵧ)] = E[XY] - E[X]E[Y] • Cov > 0 → X and Y tend to increase together • Cov < 0 → X increases when Y decreases • Cov = 0 → no linear relationship Problem: covariance depends on units and scale. Hard to interpret magnitude. Pearson Correlation: ρ = Cov(X,Y) / (σₓ × σᵧ) • Normalized version of covariance • Always between -1 and +1 • +1 = perfect positive linear relationship • -1 = perfect negative linear relationship • 0 = no linear relationship Spearman Correlation: rank-based version. Works for monotonic (not just linear) relationships. Robust to outliers. Use when data isn't normally distributed. CRITICAL: Correlation ≠ Causation. Ice cream sales and drowning both correlate with summer — confounding variable (temperature). In ML: correlated features cause multicollinearity, inflating coefficients in linear models. Remove or combine correlated features.
DIAGRAM
ρ = +1 ρ = -1 ρ = 0
● ●● ● ●
●● ●● ● ● ●
●● ●● ● ● ● ●
●● ●● ● ●
perfect perfect no linear
positive negative relationship
Covariance matrix (3 variables):
X Y Z
X [σ²ₓ Cov(X,Y) Cov(X,Z)]
Y [Cov(Y,X) σ²ᵧ Cov(Y,Z)]
Z [Cov(Z,X) Cov(Z,Y) σ²_z ]
Diagonal = variancesCODE