python kmeans 基于metric_Python metrics.homogeneity_score方法代码示例

本文展示了如何在Python中使用sklearn库的metrics模块进行KMeans聚类效果评估,特别是homogeneity_score方法。通过bench_k_means函数,演示了如何计算聚类的homogeneity、completeness、v_measure、adjusted_rand、adjusted_mutual_info和silhouette得分,这些指标有助于理解聚类质量。
摘要由CSDN通过智能技术生成

# 需要导入模块: from sklearn import metrics [as 别名]

# 或者: from sklearn.metrics import homogeneity_score [as 别名]

def bench_k_means(estimator, name, data):

estimator.fit(data)

# A short explanation for every score:

# homogeneity: each cluster contains only members of a single class (range 0 - 1)

# completeness: all members of a given class are assigned to the same cluster (range 0 - 1)

# v_measure: harmonic mean of homogeneity and completeness

# adjusted_rand: similarity of the actual values and their predictions,

# ignoring permutations and with chance normalization

# (range -1 to 1, -1 being bad, 1 being perfect and 0 being random)

# adjusted_mutual_info: agreement of the actual values and predictions, ignoring permutations

# (range 0 - 1, with 0 being random agreement and 1 being perfect agreement)

# silhouette: uses the mean distance betwee

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值