adjusted_rand_score和adjusted_mutual_info_score是用于评估聚类算法效果的指标,它们的输入通常是真实的类别标签和聚类结果。
adjusted_rand_score的输入是两个一维数组,分别表示真实的类别标签和聚类结果。代码示例如下:
from sklearn.metrics import adjusted_rand_score
# 真实的类别标签
true_labels = [0, 0, 1, 1, 1, 2, 2, 2]
# 聚类结果
cluster_labels = [1, 1, 0, 0, 0, 2, 2, 2]
# 计算调整兰德指数
score = adjusted_rand_score(true_labels, cluster_labels)
print(score)
adjusted_mutual_info_score的输入也是两个一维数组,分别表示真实的类别标签和聚类结果。代码示例如下:
from sklearn.metrics import adjusted_mutual_info_score
# 真实的类别标签
true_labels = [0, 0, 1, 1, 1, 2, 2, 2]
# 聚类结果
cluster_labels = [1, 1, 0, 0, 0, 2, 2, 2]
# 计算调整互信息得分
score = adjusted_mutual_info_score(true_labels, cluster_labels)
print(score)
以上代码示例中,真实的类别标签为true_labels
,聚类结果为cluster_labels
,调用对应的评估函数即可得到相应的评估指标得分。