sklearn.metrics.adjusted_rand_score?

sklearn.metrics.adjusted_rand_score(labels_true, labels_pred

源碼

隨機蘭德調整指數。

蘭德指數通過考慮所有樣本對并計算在預測的聚類和真實的聚類中分配在相同或不同聚類中的對來計算兩個聚類之間的相似性度量。

然后使用以下方案將原始RI分數“隨機調整”為ARI分數:

ARI = (RI - Expected_RI) / (max(RI) - Expected_RI)

因此,對于隨機標記,確保調整蘭德指數的值接近于0.0,與簇和樣本的數量無關,而當簇相同時(直到排列),恰好為1.0。

ARI是一種對稱度量:

adjusted_rand_score(a, b) == adjusted_rand_score(b, a)

用戶指南中閱讀更多內容。

參數 說明
labels_true int array, shape = [n_samples]
真實類標簽可用作參考
labels_pred array-like of shape (n_samples,)
聚類標簽以進行評估
返回值 說明
ari float
相似分數介于-1.0和1.0之間。隨機標簽的ARI接近于0.0。1.0代表完美匹配。

另見:

參考

Hubert1985 L. Hubert and P. Arabie, Comparing Partitions, Journal of Classification 1985 https://link.springer.com/article/10.1007%2FBF01908075

wk https://en.wikipedia.org/wiki/Rand_index#Adjusted_Rand_index

示例

完全匹配的標簽得分為一個偶數

>>> from sklearn.metrics.cluster import adjusted_rand_score
>>> adjusted_rand_score([0011], [0011])
1.0
>>> adjusted_rand_score([0011], [1100])
1.0

將所有類成員分配給同一類的標簽完整卻不會總是純粹的,因此會受到懲罰:

>>> adjusted_rand_score([0012], [0011])
0.57...

ARI是對稱的,因此具有純聚類且成員來自相同類但沒有不必要拆分的標簽將受到懲罰:

>>> adjusted_rand_score([0011], [0012])
0.57...

如果類成員完全分散在不同的集群中,則分配完全不完整,因此ARI非常低:

>>> adjusted_rand_score([0000], [0123])
0.0