相关系数矩阵计算
相关系数矩阵计算,忙里抽闲,加班加点,把这部分进度赶一赶,美丽的夏天开始了,这是在实验室的第五个夏天,每天的时间感觉都不够用,加油,不辜负每一天!
import numpy as np import math def getPearsonMatrix(S_mat,thresholdValue): rowCount = len(S_mat[0]) colCount = len(S_mat) R_mat=np.zeros((rowCount,colCount)) for row in range(rowCount): for col in range(colCount): if row==col: R_mat[row][col] = 1 else: S_jk = S_mat[row][col] S_jj = S_mat[row][row] S_kk = S_mat[col][col] if S_jj==0 or S_kk==0: R_mat[row][col] = 0 else: R_mat[row][col] = round(S_jk/(math.sqrt(S_jj)*math.sqrt(S_kk)),4) for row in range(len(R_mat[0])): print(R_mat[row]) return R_mat
[ 1. -0.034 -0.0034 -0.0771 0.1 0. -0.1976 -0.0058 0.1689 0.1666 -0.0433 0.0305] [-0.034 1. 0.8994 0.7335 -0.4873 0.1042 0.0693 -0.0358 -0.0998 -0.2324 -0.0095 -0.1205] [-0.0034 0.8994 1. 0.9041 -0.2412 0.1312 0.0304 0.0257 0.0067 -0.0535 -0.053 -0.0971] [-0.0771 0.7335 0.9041 1. -0.1654 0.0267 0.1096 -0.0174 0.0875 -0.0925 -0.2121 0.0038] [ 0.1 -0.4873 -0.2412 -0.1654 1. 0.3963 -0.335 0.1095 0.2622 0.6705 0.0549 0.1199] [ 0. 0.1042 0.1312 0.0267 0.3963 1. -0.2272 0.203 0.075 0.3595 0.1414 -0.1743] [-0.1976 0.0693 0.0304 0.1096 -0.335 -0.2272 1. 0.0561 -0.0138 -0.3218 0.1737 -0.0856] [-0.0058 -0.0358 0.0257 -0.0174 0.1095 0.203 0.0561 1. 0.0514 0.2059 0.2154 -0.8593] [ 0.1689 -0.0998 0.0067 0.0875 0.2622 0.075 -0.0138 0.0514 1. 0.2406 -0.0283 0.0411] [ 0.1666 -0.2324 -0.0535 -0.0925 0.6705 0.3595 -0.3218 0.2059 0.2406 1. 0.2689 -0.0592] [-0.0433 -0.0095 -0.053 -0.2121 0.0549 0.1414 0.1737 0.2154 -0.0283 0.2689 1. -0.2817] [ 0.0305 -0.1205 -0.0971 0.0038 0.1199 -0.1743 -0.0856 -0.8593 0.0411 -0.0592 -0.2817 1. ]
#################################
QQ 3087438119