Adjusted Rand index 调整兰德系数
>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]
>>> metrics.adjusted_rand_score(labels_true, labels_pred)
0.24
Mutual Information based scores 互信息
Two different normalized versions of this measure are available, Normalized Mutual Information(NMI) and Adjusted Mutual Information(AMI). NMI is often used in the literature while AMI was proposed more recently and is normalized against chance:
from sklearn import metrics
labels_true = [0, 0, 0, 1, 1, 1]
labels_pred = [0, 0, 1, 1, 2, 2]
metrics.adjusted_mutual_info_score(labels_true, labels_pred)
0.22504
.
Homogeneity, completeness and V-measure
同质性homogeneity:每个群集只包含单个类的成员。
完整性completeness:给定类的所有成员都分配给同一个群集。
>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]
>>> metrics.homogeneity_score(labels_true, labels_pred)
0.66...
>>> metrics.completeness_score(labels_true, labels_pred)
0.42...
两者的调和平均V-measure:
>>> metrics.v_measure_score(labels_true, labels_pred)
0.51...
.
Fowlkes-Mallows scores
The Fowlkes-Mallows score FMI is defined as the geometric mean of the pairwise precision and recall:
>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]
>>>
>>> metrics.fowlkes_mallows_score(labels_true, labels_pred)
0.47140...
.
Silhouette Coefficient 轮廓系数
>>> import numpy as np
>>> from sklearn.cluster import KMeans
>>> kmeans_model = KMeans(n_clusters=3, random_state=1).fit(X)
>>> labels = kmeans_model.labels_
>>> metrics.silhouette_score(X, labels, metric='euclidean')
...
0.55...
.
Calinski-Harabaz Index
这个计算简单直接,得到的Calinski-Harabasz分数值ss越大则聚类效果越好。Calinski-Harabasz分数值ss的数学计算公式是(理论介绍来源于:用scikit-learn学习K-Means聚类):
也就是说,类别内部数据的协方差越小越好,类别之间的协方差越大越好,这样的Calinski-Harabasz分数会高。
在scikit-learn中, Calinski-Harabasz Index对应的方法是metrics.calinski_harabaz_score.
在真实的分群label不知道的情况下,可以作为评估模型的一个指标。
同时,数值越小可以理解为:组间协方差很小,组与组之间界限不明显。
与轮廓系数的对比,笔者觉得最大的优势:快!相差几百倍!毫秒级
>>> import numpy as np
>>> from sklearn.cluster import KMeans
>>> kmeans_model = KMeans(n_clusters=3, random_state=1).fit(X)
>>> labels = kmeans_model.labels_
>>> metrics.calinski_harabaz_score(X, labels)
560.39...
致敬原创:http://blog.csdn.net/sinat_26917383/article/details/70577710