是否可以使用scikit-learn K-Means聚类指定自己的距离函数?
3 回答

慕虎7371278
TA贡献1802条经验 获得超4个赞
不幸的是,没有:scikit-learn当前的k-means实现仅使用欧几里得距离。
将k均值扩展到其他距离并非易事,并且denis的上述回答并不是为其他度量实施k均值的正确方法。

白衣非少年
TA贡献1155条经验 获得超0个赞
只需使用nltk即可,例如
from nltk.cluster.kmeans import KMeansClusterer
NUM_CLUSTERS = <choose a value>
data = <sparse matrix that you would normally give to scikit>.toarray()
kclusterer = KMeansClusterer(NUM_CLUSTERS, distance=nltk.cluster.util.cosine_distance, repeats=25)
assigned_clusters = kclusterer.cluster(data, assign_clusters=True)
添加回答
举报
0/150
提交
取消