2021-03-31

标题聚类中常用评价标准

评价标准的介绍:

  1. ACC
  2. AMI
  3. ARI
  4. 轮廓系数

一、ACC准确度

用来计算聚类预测的准确性 acc= 预测个数/整个样本的个数
在这里插入图片描述
n:数据的个数
l i l_i li: i的原始类别
r i r_i ri: i预测的聚类标签
map( r i r_i ri): 为预测标签到原始类别的映射
δ \delta δ(x,y): δ(x,y)定义了一个delta函数,当x = y时等于1,否则等于0。
n:数据集的个数

由于我在python中没有直接找到计算ACC的函数,一下附上自己写的方法:

from __future__ import division
import numpy as np
from munkres import Munkres,print_matrix
from sklearn import metrics

#该方法用来做从预测标签到原始类别的映射,即map(ri)
#input:ri,li
def best_map(L1,L2):
	#L1 should be the labels and L2 should be the clustering number we got
    Label1 = np.unique(L1)       # 去除重复的元素,由小大大排列
    nClass1 = len(Label1)        # 标签的大小
    Label2 = np.unique(L2)
    nClass2 = len(Label2)
    nClass = np.maximum(nClass1,nClass2)
    G = np.zeros((nClass,nClass))
    for i in range(nClass1):
        ind_cla1 = L1 == Label1[i]
        ind_cla1 = ind_cla1.astype(float)
        for j in range(nClass2):
            ind_cla2 = L2 == Label2[j]
            ind_cla2 = ind_cla2.astype(float)
            G[i,j] = np.sum(ind_cla2 * ind_cla1)
    m = Munkres()
    index = m.compute(-G.T)
    index = np.array(index)
    c = index[:,1]
    newL2 = np.zeros(L2.shape)
    for i in range(nClass2):
        newL2[L2 == Label2[i]] = Label1[c[i]]
    return newL2.astype(int)


labels_true = [0, 0, 1, 1, 2, 2]
labels_pred = [1, 1, 2, 2, 0, 0]
from sklearn.metrics import accuracy_score
print('acc',accuracy_score(labels_true,labels_pred))

二、ARI(Adjusted Rand index )调整德兰指数

其范围在[-1,1],其值越大,预测值越大,则预测值与真实值越吻合

from sklearn import metrics
 labels_true = [0, 0, 0, 1, 1, 1]
labels_pred = [0, 0, 1, 1, 2, 2]
 print(metrics.adjusted_rand_score(labels_true, labels_pred) ) 


结果:
0.24

三、AMI

其范围在[-1,1],其值越大,预测值越大,则预测值与真实值越吻合
from sklearn import metrics
labels_true = [0, 0, 0, 1, 1, 1]
labels_pred = [0, 0, 1, 1, 2, 2]
print(metrics.adjusted_mutual_info_score(labels_true, labels_pred) )

结果:
0.22504

四、轮廓系数

from sklearn.metrics import silhouette_score as SI

##data为数据 pred为预测标签
SI(data, pred)

详情看这里

还有这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值