【问题标题】:hierarchical clustering on correlations in Python scipy/numpy?Python scipy/numpy中相关性的层次聚类?
【发布时间】:2011-02-23 20:59:55
【问题描述】:

如何在scipy/numpy 中的相关矩阵上运行层次聚类?我有一个 100 行乘 9 列的矩阵,我想通过 9 个条件下每个条目的相关性来分层聚类。我想使用 1-pearson 相关性作为聚类的距离。假设我有一个包含 100 x 9 矩阵的 numpy 数组 X,我该怎么做?

我尝试使用 hcluster,基于此示例:

Y=pdist(X, 'seuclidean')
Z=linkage(Y, 'single')
dendrogram(Z, color_threshold=0)

但是,pdist 不是我想要的,因为那是欧几里得距离。有什么想法吗?

谢谢。

【问题讨论】:

    标签: python numpy cluster-analysis machine-learning scipy


    【解决方案1】:

    只需将指标更改为correlation,第一行就变成:

    Y=pdist(X, 'correlation')
    

    不过,我相信代码可以简化为:

    Z=linkage(X, 'single', 'correlation')
    dendrogram(Z, color_threshold=0)
    

    因为链接会为您处理 pdist。

    【讨论】:

    • 这里的“相关性”是指 Pearson 还是 Spearman?另外,不应该是 1 - pearson 才能成为可用于 pdist 的有效距离度量吗? pdist 会自动执行此操作吗?谢谢。
    • 在我看来它是 1 - pearson。您可以在 site-packages/scipy/spatial/distance.py 中自己查看
    • 单独提到的“相关”表示斯皮尔曼相关是相当罕见的。通常如果是 Spearman,人们会这么说,否则假设是 Pearson。
    猜你喜欢
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 2021-07-02
    • 2017-07-04
    • 1970-01-01
    • 2012-04-10
    • 2019-04-27
    相关资源
    最近更新 更多