当前位置:网站首页>Pearson correlation coefficient

Pearson correlation coefficient

2022-07-05 08:50:00 Python code doctor

# encoding:utf-8
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plot
import math
#target_url = ("https://archive.ics.uci.edu/ml/machine-learning-databases/undocumented/connectionist-bench/sonar/sonar.all-data")
#rockVMines = pd.read_csv(target_url ,header=None,prefix="V") #prefix Prefix 
rockVMines = pd.read_csv('../rockdata.txt',header=None,prefix="V")  #prefix Prefix 
row2 = rockVMines.iloc[1,0:60]
row3 = rockVMines.iloc[2,0:60]
n = len(row2)
mean2 =  row2.mean()
mean3 =  row3.mean()
t2=0 ; t3=0;t1=0
for i in range(n):
    t2 += (row2[i] - mean2) * (row2[i] - mean2) / n
    t3 += (row3[i] - mean3) * (row3[i] - mean3) / n
r23=0
for i in range(n):
    r23 += (row2[i] - mean2)*(row3[i] - mean3)/(n* math.sqrt(t2 * t3))
print(r23)

corMat = DataFrame(rockVMines.corr())  #corr  Find the correlation coefficient matrix 
print(corMat)
plot.pcolor(corMat)
plot.show()
原网站

版权声明
本文为[Python code doctor]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050841505787.html