聚类算法评价指标python实现_聚类算法的评价指标

本文介绍了如何使用Python实现聚类算法的评价指标,包括Adjusted Rand Index (ARI)和Mutual Information (MI)。ARI适用于有真实标签的情况,其值在-1到1之间,越高表示聚类效果越好。MI则通过计算两种标签分配的相似性来评估,取值范围在0到1。两者都需要真实标签作为参考,但ARI的调整使得随机聚类结果趋于0,而MI则不依赖于聚类中心和样本数的选择。
摘要由CSDN通过智能技术生成

如果有了类别标签,那么聚类结果也可以像分类那样计算准确率和召回率。scikitlearn上说:“其实不应该将分类标签作为聚类结果的评价指标,除非你有相关的先验知识或某种假设,知道这种分类类内差距更小”。但是它还是给出了几种评价标准

1. Adjusted Rand index

1.1 原理及代码实现

和分类中的acc类似,这是在计算样本预测值和真实值之间的相似度

similarity:同属于这一类或都不属于这一类 python实现的代码如下:

labels_true, labels_pred = check_clusterings(labels_true, labels_pred)

n_samples = labels_true.shape[0]

classes = np.unique(labels_true)

clusters = np.unique(labels_pred)

# Special limit cases: no clustering since the data is not split;

# or trivial clustering where each document is assigned a unique cluster.

# These are perfect matches hence return 1.0.

if (classes.shape[0] == clusters.shape[0] == 1

or classes.shape[0] == clusters.shape[0] == 0

or classes.shape[0] == clusters.shape[0] == len(labe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值