我找不到一种方法--学习,在K均值上使用相关距离度量--这对我的基因表达数据集是必要的。
但当我在互联网上搜索时,我发现了一个很好的图书馆:生物巨蟒 --它能够使用K上的相关距离度量--均值。
然而,与scikit学习不同的是,我无法获得惯性/平方误差之和,因此我无法使用'Elbow方法‘选择K(集群)的最佳数目(只有一个选项可以得到“距离的簇内和”,而不是平方!):https://biopython.org/docs/1.75/api/Bio.Cluster.html。
我如何做到这两点:使用相关距离度量和获得SSE?
发布于 2020-10-03 21:09:23
与相关距离度量相比,平方误差之和更容易实现,因此我建议您使用biopython和下面的辅助函数。它应该从数据(假设为numpy数组)和biopython的clusterid输出中为您计算平方错误的总和。
def SSE(data, clusterid):
"""
Computes the sum of squared error of the data classification.
Arguments:
data: nrows x ncolumns array containing the data values.
clusterid: array containing the number of the cluster to which each item was assigned by biopython.
"""
number_of_classes = int(clusterid.max()) + 1 #Python convention: first index is 0
sse = 0.0
for i in range(number_of_classes):
cluster = data[clusterid==i]
sse += cluster.std(ddof=len(cluster)-1)**2
return ssehttps://stackoverflow.com/questions/64161979
复制相似问题