Python中的字符串聚类 [英] String clustering in Python

查看:604
本文介绍了Python中的字符串聚类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a list of strings and I want to classify it by using clustering in Python.

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

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

I want to use Levenshtein distance, so I used jellyfish library. Given two strings, I know that their distance can be found this way:

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

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

My problem is that I don't know how to use scipy.cluster.hierarchy to get a list in Python of each cluster. I have also tried using linkage function:

linkage(y[, method, metric])

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

But I am not able to get the final list with clusters.

任何帮帮我?

推荐答案

使用链接在距离上实现分层聚类后,则应使用 cluster.hierarchy.cut_tree 剪切树。
如果要两个群集:

After using linkage for implementing hierarchical clustering on the distance you have, you should use cluster.hierarchy.cut_tree to cut the tree. If you want two clusters:

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

这篇关于Python中的字符串聚类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆