将K平均聚类距离度量更改为堪培拉距离或Python上的任何其他距离度量 [英] Changing K mean clustering distance metric to canberra distance or any other distance metric on python

查看:306
本文介绍了将K平均聚类距离度量更改为堪培拉距离或Python上的任何其他距离度量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将k均值聚类的距离度量更改为堪培拉距离或任何其他距离度量?根据我的理解,sklearn仅支持欧氏距离,而nltk似乎不支持堪培拉距离,但我可能是错的.谢谢!

How do I change the distance metric of k mean clustering to canberra distance or any other distance metric? From my understanding, sklearn only supports euclidean distance and nltk doesn't seem to support canberra distance but I may be wrong. Thank you!

推荐答案

from scipy.spatial import distance
from nltk.cluster.kmeans import KMeansClusterer

obj = KMeansCluster(num_cluster, distance = distance.canberra) 

这篇关于将K平均聚类距离度量更改为堪培拉距离或Python上的任何其他距离度量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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