Created
June 13, 2018 21:05
-
-
Save vb100/d699816fd9f5e413e95335d64c8a6bba to your computer and use it in GitHub Desktop.
Pearson Correlation Coefficient R
This file contains 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 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