我正在使用轮廓宽度来计算 k 均值中 k 的最佳值。在执行文档聚类时,我在 Python 中计算 和 的值,a如下b所示:
a = distance(data[index], centroids[clusters[index]], metric=metric, p=p)
b = min([distance(data[index], c) for i,c in enumerate(centroids) if i != currentindex])
score = float(b - a) / max(a, b) if max(a, b) > 0 else 0.0
维基百科页面的原始公式如下:

我正在使用cosine相似性度量来计算距离,并且想知道这个公式是否需要更改或者可以保持原样。在上面的代码片段中,该函数distance计算余弦相似度度量。