quantification_error и сумма квадратической ошибки (calc_sse) успешно запущены, но я не могу создать функцию индекса PBM в соответствии с https://link.springer.com/article/10.1007/s10044-015-0525-8, которая аналогична форме quanization_error и сумме квадратичной ошибки
def quantization_error(centroids: np.ndarray, labels: np.ndarray, data: np.ndarray) -> float:
error = 0.0
for i, c in enumerate(centroids):
idx = np.where(labels == i)
dist = np.linalg.norm(data[idx] - c)
dist /= len(idx)
error += dist
error /= len(centroids)
return error
def calc_sse(centroids: numpy.ndarray, labels: numpy.ndarray, data: numpy.ndarray):
distances = 0
for i, c in enumerate(centroids):
idx = numpy.where(labels == i)
dist = numpy.sum((data[idx] - c)**2)
distances += dist
return distances
def calc_sse(centroids: numpy.ndarray, labels: numpy.ndarray, data: numpy.ndarray):
distances = 0
for i, c in enumerate(centroids):
idx = numpy.where(labels == i)
dist = numpy.sum((data[idx] - c)**2)
distances += dist
return distances
`def cen1(i,j,data: np.ndarray, labels: np.ndarray, centroids: np.ndarray):
d = distance.euclidean(centroids[i],centroids[j])
return d`
def compute_R(data: np.ndarray, labels: np.ndarray, centroids: np.ndarray, nc):
list_r = []
for i in range(nc):
for j in range(nc):
if(i<j):
temp = cen1(i,j,data, labels, centroids)
list_r.append(temp)
return max(list_r)
def PBM_INDEX(centroids: np.ndarray, labels: np.ndarray, data: np.ndarray) -> float:
pbm= 0.0
for i, c in enumerate(centroids):
idx = np.where(labels == i)
#c = max(centroids)
#d = distance.euclidean(clusters[i],clusters[j])
dist = np.linalg.norm(data[idx] - c)
dist /= len(idx)
pbm += dist
pbm = (((1/len(centroids))*((calc_sse1(centroids, labels, data))/(n*error))* compute_R(data, labels, centroids))**2)
return pbm