Created
September 19, 2019 21:48
-
-
Save ssrosa/6fcbc33fc0f02c5e038e26ae31eb4491 to your computer and use it in GitHub Desktop.
For a Medium post on correlation in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_cov(X, Y): | |
| #Make sure both distributions have the same population size | |
| assert len(X) == len(Y), 'Distributions have different sizes.' | |
| muX = X.mean() | |
| muY = Y.mean() | |
| n = len(X) | |
| covariance = np.sum( | |
| (X - muX) * (Y - muY) | |
| ) / n | |
| return covariance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment