聚类算法(下):10个聚类算法的评价指标

news2024/10/1 3:17:07

上篇文章我们已经介绍了一些常见的聚类算法,下面我们将要介绍评估聚类算法的指标

1、Rand Index

Rand Index(兰德指数)是一种衡量聚类算法性能的指标。它衡量的是聚类算法将数据点分配到聚类中的准确程度。兰德指数的范围从0到1,1的值表示两个聚类完全相同,接近0的值表示两个聚类有很大的不同。需要注意的是,Rand Index只能用于评估将样本点分成两个簇的聚类算法。对于将样本点分成多个簇的聚类算法,需要使用其他的指标来评估其性能。

它的公式如下:

这里的:

a→在真实标签中处于同一簇中的样本对数,在预测聚类中处于同一簇中的样本对数。

b→真实聚类和预测聚类中处于不同聚类的样本对的数目。

要验证条件a和b,我们使用以下代码:

 ify_true[i] ==y_true[j] andy_pred[i] ==y_pred[j]:
   a+=1
 elify_true[i] !=y_true[j] andy_pred[i] !=y_pred[j]:
   b+=1
 
 #Where j= i+1

为了找到大型数组的可能组合的数量,我们可以使用math库中的“comb”函数。这个函数有两个参数n和k:

 #comb function:
 frommathimportcomb
 
 #math.comb(n,k):
 print(comb(len(df['cluster_id']),2))

以下就是python的代码实现:

 defrand_index_score(y_true, y_pred):
 
     # Initialize variables
     a, b=0,0
     
     # Compute variables
     foriinrange(len(y_true)):
         forjinrange(i+1, len(y_true)):
             ify_true[i] ==y_true[j] andy_pred[i] ==y_pred[j]:
                 a+=1
             elify_true[i] !=y_true[j] andy_pred[i] !=y_pred[j]:
                 b+=1
     #combinations
     combinations=comb(len(y_true),2)
     
     # Compute Rand Index
     rand_index= (a+b) /combinations
     print(a)
     print(b)
     
     returnrand_index
 
 #Call the function and print result:
 print(rand_index_score(df['cluster_id'], km_labels))

Sklearn已经包含了他的实现:rand_score函数,所以我们可以直接使用它

 fromsklearnimportmetrics
 
 print('Rand Index for K-Means is:', metrics.rand_score(df['cluster_id'], km_labels))
 print('Rand Index for Affinity Propagation is:', metrics.rand_score(df['cluster_id'], af_labels))
 print('Rand Index for Aglomerative Clustering is:', metrics.rand_score(df['cluster_id'], AC_labels))
 print('Rand Index for Mean Shift is:', metrics.rand_score(df['cluster_id'], MS_labels))
 print('Rand Index for Bisecting KM is:', metrics.rand_score(df['cluster_id'], BKM_labels))
 print('Rand Index for DBSCAN is:', metrics.rand_score(df['cluster_id'], DBSCAN_labels))
 print('Rand Index for OPTICS is:', metrics.rand_score(df['cluster_id'], OPTICS_labels))
 print('Rand Index for BIRCH is:', metrics.rand_score(df['cluster_id'], BIRCH_labels))

构建可视化图形

 #Build a dataframe:
 data= {'Model':["KM", "AP", "AC", "MS", "BKM", "DBSCAN", "OPTICS", "BIRCH"],'Rand_Index':[0.99, 0.93,1, 0.99, 0.94, 0.91, 0.95,1]}
 Rand_Index=pd.DataFrame(data)
 
 # Make the plot
 y_pos=np.arange(len(Rand_Index['Model']))
 
 plt.stem(Rand_Index['Rand_Index'])
 plt.xticks(y_pos, Rand_Index['Model'])
 plt.show()

2、Adjusted Rand Score

Adjusted Rand Score(调整兰德指数)是一种用于衡量聚类算法性能的指标,它是Rand Index的一种调整形式,可以用于评估将样本点分为多个簇的聚类算法。它考虑了机会的概率,取值范围为[-1,1],其中值越接近1表示聚类结果越准确,值越接近0表示聚类结果与随机结果相当,值越接近-1表示聚类结果与真实类别完全相反。

 print('Adjusted Rand Score for K-Means is:', metrics.adjusted_rand_score(df['cluster_id'], km_labels))
 print('Adjusted Rand Score for Affinity Propagation is:', metrics.adjusted_rand_score(df['cluster_id'], af_labels))
 print('Adjusted Rand Score for Aglomerative Clustering is:', metrics.adjusted_rand_score(df['cluster_id'], AC_labels))
 print('Adjusted Rand Score for Mean Shift is:', metrics.adjusted_rand_score(df['cluster_id'], MS_labels))
 print('Adjusted Rand Score for Bisecting KM is:', metrics.adjusted_rand_score(df['cluster_id'], BKM_labels))
 print('Adjusted Rand Score for DBSCAN is:', metrics.adjusted_rand_score(df['cluster_id'], DBSCAN_labels))
 print('Adjusted Rand Score for OPTICS is:', metrics.adjusted_rand_score(df['cluster_id'], OPTICS_labels))
 print('Adjusted Rand Score for BIRCH is:', metrics.adjusted_rand_score(df['cluster_id'], BIRCH_labels))
 
 data= {'Model':["KM", "AP", "AC", "MS", "BKM", "DBSCAN", "OPTICS", "BIRCH"],'Adj_Rand_Score':[0.97, 0.81,0.98, 0.97, 0.82, 0.74, 0.48, 0.92]}
 Adj_Rand_Score=pd.DataFrame(data)
 
 # Make the plot
 y_pos=np.arange(len(Adj_Rand_Score['Model']))
 
 plt.bar(y_pos,Adj_Rand_Score['Adj_Rand_Score'])
 plt.xticks(y_pos, Adj_Rand_Score['Model'])
 plt.show()

3、Mutual Information-based Score

基于互信息的分数(Mutual Information-based Score)是一种用于衡量聚类算法性能的指标,它衡量的是聚类结果与真实标签之间的相似性。基于互信息的分数可以用于评估将样本点分为多个簇的聚类算法。

基于互信息的分数的取值范围为[0,1],其中值越接近1表示聚类结果越准确,值越接近0表示聚类结果与随机结果相当,值越小表示聚类结果与真实类别之间的差异越大。基于互信息的分数是一种相对指标,它的取值受到真实类别数量的影响。当真实类别数量很大时,基于互信息的分数可能会受到偏差。

用Scikit-Learn可以计算MI:

 print('Mutual Information Based Scores for K-Means is:', metrics.mutual_info_score(df['cluster_id'], km_labels))
 print('Mutual Information Based Scores for Affinity Propagation is:', metrics.mutual_info_score(df['cluster_id'], af_labels))
 print('Mutual Information Based Scores for Aglomerative Clustering is:', metrics.mutual_info_score(df['cluster_id'], AC_labels))
 print('Mutual Information Based Scores for Mean Shift is:', metrics.mutual_info_score(df['cluster_id'], MS_labels))
 print('Mutual Information Based Scores for Bisecting KM is:', metrics.mutual_info_score(df['cluster_id'], BKM_labels))
 print('Mutual Information Based Scores for DBSCAN is:', metrics.mutual_info_score(df['cluster_id'], DBSCAN_labels))
 print('Mutual Information Based Scores for OPTICS is:', metrics.mutual_info_score(df['cluster_id'], OPTICS_labels))
 print('Mutual Information Based Scores for BIRCH is:', metrics.mutual_info_score(df['cluster_id'], BIRCH_labels))

3、Normalized Mutual Information Scor

Normalized Mutual Information Score(标准化互信息分数)是基于互信息的分数的一种标准化形式,可以用于评估将样本点分为多个簇的聚类算法。它知识将互信息分数进行了标准化,在0(表示没有互信息)和1(表示完全相关)之间进行缩放。为了标准化上一步中得到的结果,我们只需要做一点额外的工作:

 h_true=-np.sum(px*np.log(px))
 h_pred=-np.sum(py*np.log(py))
 
 nmi=mi/ ((h_true+h_pred) /2)

与基于互信息的分数相比,标准化互信息分数更加稳健,不受真实类别数量的影响。

print('Mutual Information Based Scores for K-Means is:', metrics.normalized_mutual_info_score(df['cluster_id'], km_labels))
print('Mutual Information Based Scores for Affinity Propagation is:', metrics.normalized_mutual_info_score(df['cluster_id'], af_labels))
print('Mutual Information Based Scores for Aglomerative Clustering is:', metrics.normalized_mutual_info_score(df['cluster_id'], AC_labels))
print('Mutual Information Based Scores for Mean Shift is:', metrics.normalized_mutual_info_score(df['cluster_id'], MS_labels))
print('Mutual Information Based Scores for Bisecting KM is:', metrics.normalized_mutual_info_score(df['cluster_id'], BKM_labels))
print('Mutual Information Based Scores for DBSCAN is:', metrics.normalized_mutual_info_score(df['cluster_id'], DBSCAN_labels))
print('Mutual Information Based Scores for OPTICS is:', metrics.normalized_mutual_info_score(df['cluster_id'], OPTICS_labels))
print('Mutual Information Based Scores for BIRCH is:', metrics.normalized_mutual_info_score(df['cluster_id'], BIRCH_labels))

4、Adjusted Mutual Information Score

Adjusted Mutual Information Score(调整互信息分数)是一种用于衡量聚类算法性能的指标,它是基于互信息的分数的一种调整形式,AMI不受标签数值的影响,即使标签重新排序,也会产生相同的分数。公式如下所示,其中E代表预期:

AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))]

print('Mutual Information Based Scores for K-Means is:', metrics.adjusted_mutual_info_score(df['cluster_id'], km_labels))
print('Mutual Information Based Scores for Affinity Propagation is:', metrics.adjusted_mutual_info_score(df['cluster_id'], af_labels))
print('Mutual Information Based Scores for Aglomerative Clustering is:', metrics.adjusted_mutual_info_score(df['cluster_id'], AC_labels))
print('Mutual Information Based Scores for Mean Shift is:', metrics.adjusted_mutual_info_score(df['cluster_id'], MS_labels))
print('Mutual Information Based Scores for Bisecting KM is:', metrics.adjusted_mutual_info_score(df['cluster_id'], BKM_labels))
print('Mutual Information Based Scores for DBSCAN is:', metrics.adjusted_mutual_info_score(df['cluster_id'], DBSCAN_labels))
print('Mutual Information Based Scores for OPTICS is:', metrics.adjusted_mutual_info_score(df['cluster_id'], OPTICS_labels))
print('Mutual Information Based Scores for BIRCH is:', metrics.adjusted_mutual_info_score(df['cluster_id'], BIRCH_labels))

与基于互信息的分数和标准化互信息分数相比,调整互信息分数更加稳健,可以通过随机置换进行期望值的估计,从而避免了真实类别数量的影响。

5、Homogeneity and Completeness Score

Homogeneity Score和Completeness Score是两个用于评估聚类结果的指标,它们可以用于衡量聚类算法对数据的划分是否“同质”(即簇内只包含同一类别的样本点)以及是否“完整”(即同一类别的样本点是否被划分到同一个簇中)。

同质性和完整性是给定公式的两个相关度量:

为了获得同质性和完整性,我们需要找到真实标签的熵(H)和预测标签的H,以及给定预测标签的真实标签的条件联合熵(CJH),以及给定真实标签的预测标签的CJH。

def entropy(arr):
    #Find unique values and their counts:
    unique, counts = np.unique(arr, return_counts=True)
    #Get the probability for each cluster (unique value):
    p = counts / len(arr)
    #Apply entropy formula:
    entropy = -np.sum(p * np.log2(p))
    return entropy

entropy_y_true = entropy(y_true)
entropy_km_labels = entropy(km_labels)

print('Entropy for y_true: ', entropy_y_true)
print('Entropy for km_labels: ', entropy_km_labels)

然后计算联合熵:

import numpy as np
from collections import Counter
import math

def conditional_entropy(X, Y):
    #Build a 2D-numpy array with true clusters and predicted clusters:
    XY = np.column_stack((X, Y))

    #Count the number of observations in X and Y with the same values:
    xy_counts = Counter(map(tuple, XY))

    #Get the joint probability:
    joint_prob = np.array(list(xy_counts.values())) / len(XY)

    #Get conditional probability:
    y_counts = Counter(Y)
    conditional_prob = np.zeros_like(joint_prob)
    for i, (x, y) in enumerate(xy_counts.keys()):
        conditional_prob[i] = xy_counts[(x, y)] / y_counts[y]

    #Get conditional entropy:
    conditional_entropy = -np.sum(joint_prob * np.log2(conditional_prob + 1e-10))

    return conditional_entropy

joint_entropy_y_true = conditional_entropy(y_true, km_labels)
print('Joint entropy for y_true given km_labels is: ', joint_entropy_y_true)

joint_entropy_km_labels = conditional_entropy(km_labels, y_true)
print('Joint entropy for km_labels given y_true is: ', joint_entropy_km_labels)

现在可以计算同质性和完整性值:

homogeneity = 1 - (joint_entropy_y_true / entropy_y_true)
print('homogeneity: ', homogeneity)

completeness = 1 - (joint_entropy_km_labels / entropy_km_labels)
print('Completeness: ', completeness)

当然,sklearn也提供了相关的函数

#Homogeneity:
print('Homogeneity for K-Means is:', metrics.homogeneity_score(df['cluster_id'], km_labels))
print('Homogeneity for Affinity Propagation is:', metrics.homogeneity_score(df['cluster_id'], af_labels))
print('Homogeneity for Aglomerative Clustering is:', metrics.homogeneity_score(df['cluster_id'], AC_labels))
print('Homogeneity for Mean Shift is:', metrics.homogeneity_score(df['cluster_id'], MS_labels))
print('Homogeneity for Bisecting KM is:', metrics.homogeneity_score(df['cluster_id'], BKM_labels))
print('Homogeneity for DBSCAN is:', metrics.homogeneity_score(df['cluster_id'], DBSCAN_labels))
print('Homogeneity for OPTICS is:', metrics.homogeneity_score(df['cluster_id'], OPTICS_labels))
print('Homogeneity for BIRCH is:', metrics.homogeneity_score(df['cluster_id'], BIRCH_labels))

#Completeness:
print('Completeness for K-Means is:', metrics.completeness_score(df['cluster_id'], km_labels))
print('Completeness for Affinity Propagation is:', metrics.completeness_score(df['cluster_id'], af_labels))
print('Completeness for Aglomerative Clustering is:', metrics.completeness_score(df['cluster_id'], AC_labels))
print('Completeness for Mean Shift is:', metrics.completeness_score(df['cluster_id'], MS_labels))
print('Completeness for Bisecting KM is:', metrics.completeness_score(df['cluster_id'], BKM_labels))
print('Completeness for DBSCAN is:', metrics.completeness_score(df['cluster_id'], DBSCAN_labels))
print('Completeness for OPTICS is:', metrics.completeness_score(df['cluster_id'], OPTICS_labels))
print('Completeness for BIRCH is:', metrics.completeness_score(df['cluster_id'], BIRCH_labels))

该指标的取值范围也为[0,1],值越大表示聚类结果越好。需要注意的是,该指标对簇的数量较为敏感,因此在使用时需要结合实际问题进行调参。

6、V-Measure

V-Measure是一种综合考虑同质性和完整性的评估指标,可以用于衡量聚类算法对数据的划分质量。

beta = 1

v_measure = ((1+beta)*homogeneity*completeness) / (beta*homogeneity+completeness)
print('V-Measure is: ', v_measure)

#Or simply:
metrics.v_measure_score(y_true, km_labels)

V-Measure的取值范围为[0,1],值越大表示聚类结果越好。

7、Fowlkes-Mallows Score

fowlkes - malos分数是这个是最容易理解的,它主要基于数据的真实标签和聚类结果的交集、联合集以及簇内和簇间点对数的比值来计算。由以下公式得到:

python的实现代码如下:

def fowlkes_mallows_score(labels_true, labels_pred):

    n = len(labels_true)
    tp, fp, tn, fn = 0, 0, 0, 0

    for i in range(n):
        for j in range(i + 1, n):
            if labels_true[i] == labels_true[j] and labels_pred[i] == labels_pred[j]:
                tp += 1
            elif labels_true[i] != labels_true[j] and labels_pred[i] == labels_pred[j]:
                fp += 1
            elif labels_true[i] == labels_true[j] and labels_pred[i] != labels_pred[j]:
                fn += 1
            else:
                tn += 1

    FM_score = tp / np.sqrt((tp + fp) * (tp + fn))

    return FM_score

FM_score = fowlkes_mallows_score(y_true, km_labels)
print('Fowlkes Mallows Score is: ', FM_score)

sklearn计算:

print('Fowlkes Mallows Score for K-Means is:', metrics.fowlkes_mallows_score(df['cluster_id'], km_labels))
print('Fowlkes Mallows Score for Affinity Propagation is:', metrics.fowlkes_mallows_score(df['cluster_id'], af_labels))
print('Fowlkes Mallows Score for Aglomerative Clustering is:', metrics.fowlkes_mallows_score(df['cluster_id'], AC_labels))
print('Fowlkes Mallows Score for Mean Shift is:', metrics.fowlkes_mallows_score(df['cluster_id'], MS_labels))
print('Fowlkes Mallows Score for Bisecting KM is:', metrics.fowlkes_mallows_score(df['cluster_id'], BKM_labels))
print('Fowlkes Mallows Score for DBSCAN is:', metrics.fowlkes_mallows_score(df['cluster_id'], DBSCAN_labels))
print('Fowlkes Mallows Score for OPTICS is:', metrics.fowlkes_mallows_score(df['cluster_id'], OPTICS_labels))
print('Fowlkes Mallows Score for BIRCH is:', metrics.fowlkes_mallows_score(df['cluster_id'], BIRCH_labels))

以上这些指标都是当我们知道真正的类的标签是可以使用(还记得上一篇中我们的cluster_id吗),这些评估聚类方法的指标是可解释的。下面我们将介绍一些不知道真正的类时评估聚类指标的指标。

8、Silhouette Score

轮廓分数使用同一聚类中的点之间的距离,以及下一个临近聚类中的点与所有其他点之间的距离来评估模型的表现。它主要基于样本点与其所属簇内和最近邻簇之间的距离、相似性和紧密度等因素来计算。数值越高,模型性能越好。一般公式为:

这里的:

a→样本与同类中所有其他点之间的平均距离。

b→样本与下一个最近聚类中所有其他点之间的平均距离。

要在Python中实现Silhouette Score公式,我们可以使用以下代码:

n_samples = len(X)
cluster_labels = np.unique(km_labels)

n_clusters = len(cluster_labels)
silhouette_vals = np.zeros(n_samples)

for i in range(n_samples):
    a_i = np.mean([np.linalg.norm(X[i] - X[j]) for j in range(n_samples) if km_labels[j] == km_labels[i] and j != i])
    b_i = np.min([np.mean([np.linalg.norm(X[i] - X[j]) for j in range(n_samples) if km_labels[j] == k]) for k in cluster_labels if k != km_labels[i]])
    silhouette_vals[i] = (b_i - a_i) / max(a_i, b_i)

silhouette_score = np.mean(silhouette_vals)
print(silhouette_score)

sklearn的实现:

print('Silhouette Coefficient for K-Means is:', metrics.silhouette_score(X, km_labels, metric='euclidean'))
print('Silhouette Coefficient for Affinity Propagation is:', metrics.silhouette_score(X, af_labels, metric='euclidean'))
print('Silhouette Coefficient for Aglomerative Clustering is:', metrics.silhouette_score(X, AC_labels, metric='euclidean'))
print('Silhouette Coefficient for Mean Shift is:', metrics.silhouette_score(X, MS_labels, metric='euclidean'))
print('Silhouette Coefficient for Bisecting KM is:', metrics.silhouette_score(X, BKM_labels, metric='euclidean'))
print('Silhouette Coefficient for DBSCAN is:', metrics.silhouette_score(X, DBSCAN_labels, metric='euclidean'))
print('Silhouette Coefficient for OPTICS is:', metrics.silhouette_score(X, OPTICS_labels, metric='euclidean'))
print('Silhouette Coefficient for BIRCH is:', metrics.silhouette_score(X, BIRCH_labels, metric='euclidean'))

Silhouette Score还可以用于确定聚类的最优簇数。通过计算不同簇数下的Silhouette Score,可以选择使得Silhouette Score最大的簇数作为最终的聚类结果。

9、Calinski-Harabasz Index

Calinski-Harabasz Index(也称Variance Ratio Criterion)是一种用于衡量聚类算法性能的指标,它主要基于簇内和簇间方差之间的比值来计算。

tr(B)和tr(W)分别表示簇间协方差矩阵和簇内协方差矩阵的迹。Calinski-Harabasz Index的取值范围为[0, +\infty),值越大表示聚类结果越好。

Calinski-Harabasz Index也可以用于确定聚类的最优簇数。通过计算不同簇数下的Calinski-Harabasz Index,可以选择使得Calinski-Harabasz Index最大的簇数作为最终的聚类结果。以下是python的代码实现:

def calinski_harabasz_score(X, labels):
    n_samples, _ = X.shape
    n_labels = len(np.unique(labels))
    if n_labels == 1:
        return np.nan
    mean = np.mean(X, axis=0)
    extra_disp, intra_disp = 0., 0.
    for k in range(n_labels):
        cluster_k = X[labels == k]
        mean_k = np.mean(cluster_k, axis=0)
        extra_disp += cluster_k.shape[0] * np.sum((mean_k - mean) ** 2)
        intra_disp += np.sum((cluster_k - mean_k) ** 2)
    chs = (extra_disp / (n_labels - 1)) / (intra_disp / (n_samples - n_labels))
    return chs

CHS = calinski_harabasz_score(X, km_labels)
print(CHS)

sklearn的实现我们可以直接使用

print('Calinski-Harabasz Index for K-Means is:', metrics.calinski_harabasz_score(X, km_labels))
print('Calinski-Harabasz Index for Affinity Propagation is:', metrics.calinski_harabasz_score(X, af_labels))
print('Calinski-Harabasz Index for Aglomerative Clustering is:', metrics.calinski_harabasz_score(X, AC_labels))
print('Calinski-Harabasz Index for Mean Shift is:', metrics.calinski_harabasz_score(X, MS_labels))
print('Calinski-Harabasz Index for Bisecting KM is:', metrics.calinski_harabasz_score(X, BKM_labels))
print('Calinski-Harabasz Index for DBSCAN is:', metrics.calinski_harabasz_score(X, DBSCAN_labels))
print('Calinski-Harabasz Index for OPTICS is:', metrics.calinski_harabasz_score(X, OPTICS_labels))
print('Calinski-Harabasz Index for BIRCH is:', metrics.calinski_harabasz_score(X, BIRCH_labels))

10、Davies-Bouldin Index

Davies-Bouldin Index主要基于簇内的紧密度和簇间的分离度来计算。Davies-Bouldin Index的取值范围为[0, +\infty),值越小表示聚类结果越好。

python代码实现:

def euclidean_distance(x, y):
    return np.sqrt(np.sum((x - y)**2))

def davies_bouldin(X, labels):
    n_clusters = len(np.bincount(labels))
    cluster_k = [X[labels == k] for k in range(n_clusters)]
    centroids = [np.mean(k, axis=0) for k in cluster_k]

    db_indices = []
    for i, k_i in enumerate(cluster_k):
        s_i = np.mean([np.linalg.norm(x - centroids[i]) for x in k_i])
        R = []
        for j, k_j in enumerate(cluster_k):
            if j != i:
                s_j = np.mean([np.linalg.norm(x - centroids[j]) for x in k_j])
                dist = np.linalg.norm(centroids[i] - centroids[j])
                R.append((s_i + s_j) / dist)
        db_indices.append(np.max(R))
    return np.mean(db_indices)

DB_Index = davies_bouldin(X, km_labels)
print(DB_Index)

sklearn:

print('Davies-Bouldin Index for K-Means is:', metrics.davies_bouldin_score(X, km_labels))
print('Davies-Bouldin Index for Affinity Propagation is:', metrics.davies_bouldin_score(X, af_labels))
print('Davies-Bouldin Index for Aglomerative Clustering is:', metrics.davies_bouldin_score(X, AC_labels))
print('Davies-Bouldin Index for Mean Shift is:', metrics.davies_bouldin_score(X, MS_labels))
print('Davies-Bouldin Index for Bisecting KM is:', metrics.davies_bouldin_score(X, BKM_labels))
print('Davies-Bouldin Index for DBSCAN is:', metrics.davies_bouldin_score(X, DBSCAN_labels))
print('Davies-Bouldin Index for OPTICS is:', metrics.davies_bouldin_score(X, OPTICS_labels))
print('Davies-Bouldin Index for BIRCH is:', metrics.davies_bouldin_score(X, BIRCH_labels))

总结

在聚类算法中,评估聚类结果的好坏是非常重要的。常见的聚类评估指标包括:

  • Rand Index:用于衡量聚类结果和真实标签之间的相似度。
  • Adjusted Rand Score:Rand Index的调整版本,可以对随机结果进行惩罚。
  • Mutual Information Score(基于互信息的分数):衡量聚类结果和真实标签之间的相似度。
  • Normalized Mutual Information Score:Mutual Information Score的归一化版本。
  • Adjusted Mutual Information Score:Normalized Mutual Information Score的调整版本。
  • Homogeneity and Completeness Score:分别衡量聚类结果的同质性和完整性。
  • V-Measure:基于Homogeneity和Completeness Score计算的综合评估指标。
  • Fowlkes-Mallows Score:用于衡量聚类结果和真实标签之间的相似度。
  • Silhouette Score:用于衡量聚类结果中每个样本点与自身簇和其他簇之间的相似度。
  • Calinski-Harabasz Index:基于簇内和簇间方差之间的比值来计算聚类性能。
  • Davies-Bouldin Index:基于簇内的紧密度和簇间的分离度来计算聚类性能。

需要根据具体的问题选择适合的评估指标,并结合实际情况进行调参。

https://avoid.overfit.cn/post/abf0739d6877426ca63870cac6202e2c

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/374705.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Python-GEE遥感云大数据分析、管理与可视化技术及多领域案例实践应用

随着航空、航天、近地空间等多个遥感平台的不断发展,近年来遥感技术突飞猛进。由此,遥感数据的空间、时间、光谱分辨率不断提高,数据量也大幅增长,使其越来越具有大数据特征。对于相关研究而言,遥感大数据的出现为其提…

【阿旭机器学习实战】【37】电影推荐系统---基于矩阵分解

【阿旭机器学习实战】系列文章主要介绍机器学习的各种算法模型及其实战案例,欢迎点赞,关注共同学习交流。 电影推荐系统 目录电影推荐系统1. 问题介绍1.1推荐系统矩阵分解方法介绍1.2 数据集:ml-100k2. 推荐系统实现2.1 定义矩阵分解函数2.2 …

什么牌子的蓝牙耳机便宜好用?四款高品质蓝牙耳机推荐

随着时代的发展,蓝牙耳机的使用频率越来越高,不少人外出时除了带手机外,蓝牙耳机也成为了外出必备的数码产品之一。现在的蓝牙耳机品牌众多,什么牌子的蓝牙耳机便宜好用?下面,我来给大家推荐四款高品质的蓝…

ZigBee组网原理详解

关键词:RFD FFD ZigBee 1. 组网概述 组建一个完整的zigbee网状网络包括两个步骤:网络初始化、节点加入网络。其中节点加入网络又包括两个步骤:通过与协调器连接入网和通过已有父节点入网。 ZigBee网络中的节点主要包含三个:终端…

一文3000字从0到1实现基于Selenium+Python的web自动化测试框架 (建议收藏)

一、什么是Selenium? Selenium是一个基于浏览器的自动化测试工具,它提供了一种跨平台、跨浏览器的端到端的web自动化解决方案。Selenium主要包括三部分:Selenium IDE、Selenium WebDriver 和Selenium Grid。 Selenium IDE:Firefo…

阿里云服务器宝塔phpstudyIIS建站

P1 建站准备工作 1.购买云服务器 (新用户登录阿里云有阿里云服务器一个月的试用权限,但是试用期的云服务器有地区限制(不可自己选择地区),我的显示的是杭州,内地的服务器进行域名绑定的话,需要…

香港新世代加密资产网红正在崛起

2023年,历经兴衰的加密资产,在元宇宙和NFT的影响下,越来越多人开始关注这个领域。而在香港,不同的人更是成为了加密资产网红,引起加密资产热度的提升。香港加密资产政策促进网红崛起随着加密资产在全球的兴起&#xff…

OPPO手机删除文件数据恢复技巧篇

由于各种原因,所有 Android 手机上的数据都可能丢失。Oppo也是一个专注于Android操作系统的智能手机品牌。因此,您的 Oppo 设备上的数据也容易被删除和损坏。在本文中,我们将讨论 Oppo 用户恢复丢失或删除数据的不同方式。我们将详细讲解OPPO…

原始GAN-pytorch-生成MNIST数据集(原理)

文章目录1. GAN 《Generative Adversarial Nets》1.1 相关概念1.2 公式理解1.3 图片理解1.4 熵、交叉熵、KL散度、JS散度1.5 其他相关(正在补充!)1. GAN 《Generative Adversarial Nets》 Ian J. Goodfellow, Jean Pouget-Abadie, Yoshua Be…

string类的理解以及模拟实现

string类的理解为什么需要学习string类标准库中的string类string类简单了解string类常见接口string模拟实现深浅拷贝问题标准库下的stringVS环境下g环境下为什么需要学习string类 在C语言中,字符串和字符串相关的函数是分开的,不太符合面向对象的思想&a…

在线视频加密播放与防下载该如何考虑?

在线视频加密播放与防下载该如何考虑? ▲ 图 / 防录屏随机水印 1. 视频加密(分片加密)VRM加密: 将视频进行切片、对碎片逐一进行混淆式加密,包括AES128加密、XOR加密、关键帧错序等。 2. 防录屏(用名信息I…

IM即时通讯开发如何解决大量离线消息导致客户端卡顿的

大部分做后端开发的朋友,都在开发接口。客户端或浏览器h5通过HTTP请求到我们后端的Controller接口,后端查数据库等返回JSON给客户端。大家都知道,HTTP协议有短连接、无状态、三次握手四次挥手等特点。而像游戏、实时通信等业务反而很不适合用…

一个Laravel+vue免费开源的基于RABC控制的博客系统

项目介绍 CCENOTE 是一个使用 Vue3 Laravel8 开发的前后端分离的基于RABC权限控制管理的内容管理系统,由于作者本人比较喜欢写作的原因,因此开发了这个项目,后端使用的PHP的Laravel框架,并且整理了数据层与业务层,相…

node环境搭建以及接口的封装

node环境搭建 文章目录node环境搭建1.在cmd中输入命令安装express(全局)2.在自己的项目下安装serve3.测试接口4.连接mysql4.1 创建数据表4.2 在serve目录下建db下的sql.js4.3 sql.js4.4 在serve路径下安装mysql4.5 在routes 中引入并发送请求4.6 请求到数…

一文3000字从0到1教你用python+selenium搭建UI自动化测试环境以及使用

一、什么是Selenium ? Selenium 是一个浏览器自动化测试框架,它主要用于web应用程序的自动化测试,其主要特点如下:开源、免费;多平台、浏览器、多语言支持;对web页面有良好的支持;API简单灵活易…

STM32CubeMX串口USART中断发送接收数据

本文代码使用 HAL 库。 文章目录前言一、中断控制二、USART中断使用1. 中断优先级设置 :2. 使能中断3. 使能UART的发送、接收中断4. 中断收发函数5. 中断处理函数6. 中断收发回调函数三、串口中断实验串口中断发送数据点亮 led:实验现象:总结…

excel图表制作:旋风图让数据对比更直观

旋风图是我们工作中最常用的数据对比图表。旋风图中两组图表背靠背,纵坐标同向,横坐标反向。今天我们就跟大家分享两种制作旋风图的方式。如下表所示,我们以某平台各主要城市的男女粉丝数据为例,制作旋风图来对比男女用户情况。一…

中级嵌入式系统设计师2016下半年下午应用设计试题

中级嵌入式系统设计师2016下半年下午试题 试题一 阅读以下说明,回答问题1至问题3。 【说明】 某综合化智能空气净化器设计以微处理器为核心,包含各种传感器和控制器,具有检测环境空气参数(包含温湿度、可燃气体、细颗粒物等),空气净化、加湿、除湿、加热和杀菌等功能…

7、算法MATLAB ---(运算符)(语句)

运算符&语句1.关系运算符2.逻辑运算符3. if...else 控制语句4. for循环5. While循环6.控制循环退出的关键字6.1 Break6.2 Continue6.3 Return1.关系运算符 ">"大于 ">"大于等于 "<"小于 "<"小于等于 ""等于…

【第六章 JdbcTemplate概念和准备,JdbcTemplate操作数据库(添加)】

第六章 JdbcTemplate概念和准备&#xff0c;JdbcTemplate操作数据库&#xff08;添加&#xff09; 1.JdbcTemplate&#xff08;概念和准备&#xff09; &#xff08;1&#xff09;spring框架对jdbc进行封装&#xff0c;使用JdbcTemplate方便实现对数据库操作。 &#xff08;2&…