Skip to content

Instantly share code, notes, and snippets.

@ssrosa
Created September 19, 2019 21:48
Show Gist options
  • Select an option

  • Save ssrosa/6fcbc33fc0f02c5e038e26ae31eb4491 to your computer and use it in GitHub Desktop.

Select an option

Save ssrosa/6fcbc33fc0f02c5e038e26ae31eb4491 to your computer and use it in GitHub Desktop.
For a Medium post on correlation in Python
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