probml / pmtk3

Probabilistic Modeling Toolkit for Matlab/Octave.
MIT License
1.55k stars 797 forks source link

Add a correlation_demo #109

Closed ghost closed 8 years ago

ghost commented 8 years ago

https://en.wikipedia.org/wiki/Correlation_and_dependence#/media/File:Correlation_examples2.svg corr(X, Y) == 1 iff y = a * x + b

The following code demonstrates the above linked image, which is included in ML 1st Edition. There are two sliders in the UI that allow a user to change the rotation and aspect ratio of the 2D point cloud. The corr(X, Y) value is also displayed.

A line fitted by linear regression on the 2D point cloud is also shown. The SSE of linear regression satisfies: SSE / cov(Y,Y) = 1 - corr(X,Y). Thus SSE == 0 iff corr(X,Y) == 1