python输出特征相关矩阵_python – 两个特征矩阵的有效成对相关

似乎scipy.stats.pearsonr遵循Pearson相关系数公式的这个定义,该公式应用于来自A& A的列方对. B – 基于该公式,您可以轻松地进行矢量化,因为来自A和B的列的成对计算彼此独立.这是使用broadcasting的一个矢量化解决方案 –# Get number of rows in either A or BN = B.shape[0]# Store columnw...
摘要由CSDN通过智能技术生成

似乎

scipy.stats.pearsonr遵循Pearson相关系数公式的这个定义,该公式应用于来自A& A的列方对. B –

V9dfd.jpg

基于该公式,您可以轻松地进行矢量化,因为来自A和B的列的成对计算彼此独立.这是使用broadcasting的一个矢量化解决方案 –

# Get number of rows in either A or B

N = B.shape[0]

# Store columnw-wise in A and B, as they would be used at few places

sA = A.sum(0)

sB = B.sum(0)

# Basically there are four parts in the formula. We would compute them one-by-one

p1 = N*np.einsum('ij,ik->kj',A,B)

p2 = sA*sB[:,None]

p3 = N*((B**2).sum(0)) - (sB**2)

p4 = N*((A**2).sum(0)) - (sA**2)

# Finally compute Pearson Correlation Coefficient as 2D array

pcorr = ((p1 - p2)/np.sqrt(p4*p3[:,None]))

# Get the element corresponding to absolute argmax along the columns

out = pcorr[np.nanargma

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值