Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scipy: Pearson's correlation always returning 1

I am using Python library scipy to calculate Pearson's correlation for two float arrays. The returned value for coefficient is always 1.0, even if the arrays are different. For example:

[-0.65499887  2.34644428]
[-1.46049758  3.86537321]

I am calling the routine in this way:

r_row, p_value = scipy.stats.pearsonr(array1, array2)

The value of r_row is always 1.0. What am I doing wrong?

like image 412
user2291379 Avatar asked Apr 17 '13 15:04

user2291379


1 Answers

Pearson's correlation coefficient is a measure of how well your data would be fitted by a linear regression. If you only provide it with two points, then there is a line passing exactly through both points, hence your data perfectly fits a line, hence the correlation coefficient is exactly 1.

like image 170
Jaime Avatar answered Nov 15 '22 19:11

Jaime