小编use*_*686的帖子

如何使用sklearn CCA模块计算相关系数?

我需要使用 CCA 模块来测量特征向量之间的相似性。我看到 sklearn 有一个很好的 CCA 模块可用:https://scikit-learn.org/stable/modules/ generated/sklearn.cross_decomposition.CCA.html

在我审阅的不同论文中,我发现使用 CCA 测量相似性的方法是计算相关系数的平均值,例如在以下笔记本示例中所做的: https: //github.com/google/svcca/blob/ 1f3fbf19bd31bd9b76e728ef75842aa1d9a4cd2b/tutorials/001_Introduction.ipynb

如何使用sklearn CCA模块计算相关系数(如笔记本中所示)?

from sklearn.cross_decomposition import CCA
import numpy as np

U = np.random.random_sample(500).reshape(100,5)
V = np.random.random_sample(500).reshape(100,5)

cca = CCA(n_components=1)
cca.fit(U, V)

cca.coef_.shape                   # (5,5)

U_c, V_c = cca.transform(U, V)

U_c.shape                         # (100,1)
V_c.shape                         # (100,1)
Run Code Online (Sandbox Code Playgroud)

这是 sklearn CCA 模块的一个示例,但是我不知道如何从中检索相关系数。

python scikit-learn

7
推荐指数
1
解决办法
2644
查看次数

标签 统计

python ×1

scikit-learn ×1