Python K-medoids可视化

时间:2016-08-09 11:49:30

标签: python cluster-analysis

这段代码来自互联网。我申请我的数据和工作。所以我试着展示这种方法的可视化,但我找不到k-medoids的相关可视化代码。

from nltk.metrics import distance as distance
import Pycluster as PC
words = ['apple', 'Doppler', 'applaud', 'append', 'barker', 
     'baker', 'bismark', 'park', 'stake', 'steak', 'teak', 'sleek']
dist = [distance.edit_distance(words[i], words[j])
    for i in range(1, len(words))
    for j in range(0, i)]

clusterid, error, nfound = PC.kmedoids(dist, nclusters=3)
cluster = dict()

uniqid=list(set(clusterid))
new_ids = [ uniqid.index(val) for val in clusterid]
for word, label in zip(words, clusterid):
   cluster.setdefault(label, []).append(word)
for label, grp in cluster.items():
    print(grp)

1 个答案:

答案 0 :(得分:1)

您的输入数据是

你如何想象他们?它们不是坐标向量。