【问题标题】:Clustering with Scipy in Python? (hierarchical clustering)在 Python 中使用 Scipy 进行聚类? (层次聚类)
【发布时间】:2013-11-10 02:01:04
【问题描述】:

我对在 Python 中使用 Scipy 进行聚类有点困惑。这是我的源代码:

import scipy.spatial.distance as dist
import numpy, scipy

dataMatrix = numpy.array(matrix)
distMatrix = dist.pdist(dataMatrix, 'euclidean')
distSquareMatrix = dist.squareform(distMatrix)

Y = scipy.cluster.hierarchy.linkage(distSquareMatrix, method='complete')

我是否必须使用“distMatrix”或方形“distSquareMatrix”作为聚类的输入?因为我在其他帖子中看到了这两种方法。但是输出不一样。现在我不确定我必须选择什么。

【问题讨论】:

    标签: python python-2.7 scipy hierarchical-clustering


    【解决方案1】:

    您需要以压缩形式传递距离矩阵,而无需使用squareform 对其进行转换。 squareform 如果您想自己更轻松地将距离矩阵作为 2D 数组进行操作,则该函数很有用。 scipy.cluster.hierarchy 函数使用压缩形式来节省大约两倍的内存。

    我希望这会有所帮助。

    【讨论】:

    • 感谢您的回答!这意味着我必须在链接函数中使用“distMatrix”...
    猜你喜欢
    • 2013-07-11
    • 1970-01-01
    • 2021-01-15
    • 2019-04-27
    • 2021-07-02
    • 2014-10-03
    • 2011-02-23
    • 2018-08-17
    • 2019-10-24
    相关资源
    最近更新 更多