Note

Numpy (36) 본문

Numpy

Numpy (36)

알 수 없는 사용자 2022. 8. 28. 22:19
728x90

How to find the correlation between two columns of a numpy array?

# Input
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
iris = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0,1,2,3])

# 1
np.corrcoef(iris[:, 0], iris[:, 2])[0, 1]

# 2
from scipy.stats.stats import pearsonr  
corr, p_value = pearsonr(iris[:, 0], iris[:, 2])
print(corr)

# output
0.871754157305

'Numpy' 카테고리의 다른 글

Numpy (38)  (0) 2022.08.30
Numpy (37)  (0) 2022.08.29
Numpy (35)  (0) 2022.08.27
Numpy (34)  (0) 2022.08.26
Numpy (33)  (0) 2022.08.25
Comments