# 导入库 import numpy as np from scipy.stats import pearsonr import csv # 导入数据 Housing_dataset = np.loadtxt(r"D:\neural networks\YOLOX-main\Train_345.csv", delimiter="," ,dtype='float64',skiprows=0) # 切分数据 X = Housing_dataset[:, :8] y = Housing_dataset[:,7].reshape(-1, 1) # 输出X,y的维度 print(X.shape) print(y.shape) # Pearsonr分析 for i in range(8): x = X[:, i].reshape(-1, 1) x = np.squeeze(x) y = np.squeeze(y) # print(x.shape) # ------------pearsonr(x,y)------------- result = pearsonr(x, y) # ------------保存结果-------------------- print(result) with open('pearson.csv', 'a+', encoding='utf-8', newline="")as file_write: result_writer = csv.writer(file_write) result_writer.writerow(result)
结果:
(23186, 8)
(23186, 1)
(0.390683095221516, 0.0)
(0.18241386058426853, 1.2316591621612489e-172)
(0.2814844413956121, 0.0)
(0.36491437308758456, 0.0)
(0.19467749938433787, 8.352024672327669e-197)
(0.10470869965723154, 1.5732394786086808e-57)
(0.511663840712641, 0.0)
(0.9999999999999999, 0.0)