相关距离度量和误差平方和
Correlation Distance Metric and Sum of Squared Errors
我找不到使用 scikit-learn 的方法来在 K-Means 上使用相关距离度量——这对我的基因表达数据集来说是必需的。
但是在互联网上搜索时,我发现了这个很棒的库:biopython - 它能够在 K-Means 上使用相关距离度量。
但是,与 scikit-learn 不同,我无法获得惯性/误差平方和,因此我无法使用 'Elbow Method'(只有获取“错误”值的选项,该值是“簇内距离总和” - 不是平方!):https://biopython.org/docs/1.75/api/Bio.Cluster.html
我怎样才能同时做到:使用相关距离度量 和 获得 SSE?
误差平方和比相关距离度量更容易实现,因此我建议您将 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 sse
我找不到使用 scikit-learn 的方法来在 K-Means 上使用相关距离度量——这对我的基因表达数据集来说是必需的。
但是在互联网上搜索时,我发现了这个很棒的库:biopython - 它能够在 K-Means 上使用相关距离度量。
但是,与 scikit-learn 不同,我无法获得惯性/误差平方和,因此我无法使用 'Elbow Method'(只有获取“错误”值的选项,该值是“簇内距离总和” - 不是平方!):https://biopython.org/docs/1.75/api/Bio.Cluster.html
我怎样才能同时做到:使用相关距离度量 和 获得 SSE?
误差平方和比相关距离度量更容易实现,因此我建议您将 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 sse