adjusted rand index和adjusted mutual information score

这段代码演示了如何使用`sklearn.metrics`中的`adjusted_rand_score`和`adjusted_mutual_info_score`来评估随机生成的标签分配。通过对不同数量的聚类(2到100)进行多次运行,计算平均得分和标准差,展示两者在随机标签情况下的性能差异。
摘要由CSDN通过智能技术生成
import matplotlib.pyplot as plt
import numpy as np
from sklearn import metrics


def uniform_labelings_scores(score_func, n_samples, n_clusters_range, fixed_n_classes=None, n_runs=5, seed=42):
    random_labels = np.random.RandomState(seed).random_integers
    scores = np.zeros((len(n_clusters_range), n_runs))
    for i, k in enumerate(n_clusters_range):
        for j in range(n_runs):
            if fixed_n_classes is None:
                labels_a = random_labels(low=1, high=k, size=n_samples)
            else:
                labels_a = random_labels(low=1, high=fixed_n_classes, size=n_samples)
            labels_b = random_labels(low=1, high=k, size=n_samples)
            scores[i, j] = score_func(labels_a, labels_b)
    return scores


score_funcs = [metrics.adjusted_rand_score, metrics.adjusted_mutual_info_score]
n_samples = 100
n_clusters_range = map(int, np.lin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值