Skip to content

Instantly share code, notes, and snippets.

@vb100
Created June 13, 2018 21:05
Show Gist options
  • Save vb100/d699816fd9f5e413e95335d64c8a6bba to your computer and use it in GitHub Desktop.
Save vb100/d699816fd9f5e413e95335d64c8a6bba to your computer and use it in GitHub Desktop.
Pearson Correlation Coefficient R
def pearson_r(x, y):
"""Compute Pearson correlation coefficient between two arrays."""
# Compute correlation matrix: corr_mat
corr_mat = np.corrcoef(x, y)
# Return entry [0,1]
return corr_mat[0,1]
# Compute Pearson correlation coefficient for I. versicolor: r
r = pearson_r(versicolor_petal_length, versicolor_petal_width)
# Print the result
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment