【问题标题】:String clustering in PythonPython中的字符串聚类
【发布时间】:2016-08-25 06:59:22
【问题描述】:

我有一个字符串列表,我想通过在 Python 中使用聚类对其进行分类。

list = ['String1', 'String2', 'String3',...]

我想使用 Levenshtein 距离,所以我使用了 jellyfish 库。给定两个字符串,我知道可以通过这种方式找到它们的距离:

jellyfish.levenshtein_distance('string1', 'string2')

我的问题是我不知道如何使用scipy.cluster.hierarchy 在 Python 中获取每个集群的列表。我也尝试过使用链接功能:

linkage(y[, method, metric])

但我无法获得包含集群的最终列表。

【问题讨论】:

标签: python string scipy cluster-analysis


【解决方案1】:

使用linkage对你的距离进行层次聚类后,你应该使用cluster.hierarchy.cut_tree来切割树。 如果你想要两个集群:

cluster.hierarchy.cut_tree(linkage_output,2).ravel() #.ravel makes it 1D array.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-12
    • 2011-05-13
    • 2016-07-11
    • 2014-06-13
    • 1970-01-01
    • 2012-01-02
    • 2015-08-22
    • 1970-01-01
    相关资源
    最近更新 更多