相关疑难解决方法(0)

我的 Davies-Bouldin 索引的 python 实现正确吗?

我正在尝试用Python计算Davies-Bouldin 指数。

以下是下面的代码尝试重现的步骤。

5 个步骤

  1. 对于每个簇,计算每个点到质心之间的欧氏距离
  2. 对于每个簇,计算这些距离的平均值
  3. 对于每对簇,计算它们质心之间的欧氏距离

然后,

  1. 对于每对簇,求其到各自质心的平均距离之和(在步骤 2 中计算),并将其除以它们之间的距离(在步骤 3 中计算)。

最后,

  1. 计算所有这些划分(=所有索引)的平均值以获得整个聚类的 Davies-Bouldin 索引

代码

def daviesbouldin(X, labels, centroids):

    import numpy as np
    from scipy.spatial.distance import pdist, euclidean
    
    nbre_of_clusters = len(centroids) #Get the number of clusters
    distances = [[] for e in range(nbre_of_clusters)] #Store intra-cluster distances by cluster
    distances_means = [] #Store the mean of these distances
    DB_indexes = [] #Store Davies_Boulin index of each pair of cluster
    second_cluster_idx = [] #Store index of …
Run Code Online (Sandbox Code Playgroud)

python statistics metrics cluster-analysis data-science

5
推荐指数
1
解决办法
9877
查看次数