COSC 3430 · Artificial Intelligence

Pearson's r, Point by Point

Drag the points and watch the correlation coefficient change. Every point adds one term to the formula: teal when it sits on the same side of both means, burgundy when it sits on opposite sides. The shaded rectangles are those terms, drawn to scale. Start with the dogs and cats data from class.
same side of both means: positive term opposite sides: negative term means
Pearson's r —
positive terms (sum) —
negative terms (sum) —
numerator Σ(a−ā)(b−b̄) —
points n —
r = Σ(a−ā)(b−b̄) / √( Σ(a−ā)² · Σ(b−b̄)² )

Drag a point to move it. Click an empty spot to add a point; double-click a point to remove it. Keyboard: tab to a point, move it with the arrow keys (hold shift for bigger steps), remove it with Delete.

The same number as a cosine

Subtract each column's mean. The two centered columns are vectors with one entry per point. Pearson's r is the cosine of the angle between them, the same cosine similarity you used for the movie recommender. Without the centering you would get a different number.

angle θ between the centered columns —
cos θ —

Every term, one row per point

#aba − āb − b̄term

Reading r

Built to accompany COSC 3430 (Artificial Intelligence), end-to-end ML project, part 4 (correlations). Everything here computes live in the browser from the actual formula; check it against df.corr() in your notebook.