Covariance tells you the direction of a relationship but its size depends on the units. Pearson correlation divides that away, landing on a fixed scale from -1 to 1:
1 Σ (x - mean_x)(y - mean_y)2r = ---------------------------------------------3 sqrt(Σ (x - mean_x)² * Σ (y - mean_y)²)
Task: write pearson_correlation(x_values, y_values) returning r, rounded to 4 decimal places.
1.0 is a perfect increasing straight line, -1.0 a perfect decreasing one, 0.0 no linear relationship.0.0.It only measures linear association. Points on a perfect parabola have an exact, deterministic relationship and can still score near zero — which is the standard argument for looking at a scatter plot before trusting any single correlation number.
Once your code passes every test, a reference solution shows up here so you can compare it with yours.
Hover over a point to inspect its centered deviations and cross-product!
The Pearson r numerator is the sum of (x − x̄)(y − ȳ). When both variables deviate in the same direction — both above their means, or both below — the product is positive, pushing r towards +1.