我正在尝试用Python计算Davies-Bouldin 指数。
以下是下面的代码尝试重现的步骤。
5 个步骤:
然后,
最后,
代码
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)