-2
我從互聯網上得到的這段代碼。我適用於我的數據和工作。所以我試圖展示這種方法的可視化,但我無法找到k-medoids的相關可視化代碼。Python 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)
有沒有辦法讓它工作?像levenshtein距離? – user2717427
這對於可視化有什麼幫助? Levenshtein是編輯距離系列的一部分。 –