顺序 k 均值
Sequential k-means
我可以使用之前 Kmeans 拟合的 cluster_center 坐标作为初始参数,以便在新数据到达时按顺序更新 cluster_center 坐标吗?这种方法有什么缺点吗?
已更新在线版 Scikit 学习 K-means:
KM = KMeans(n_clusters=3, random_state = 200, n_init = 1)
ni = 0
Until interrupted:
for x in data:
KM_updated = KM.fit(x)
Updated_centroids(i) = KM_updated.cluster_centers_(i) + 1/len(KM_updated.labels_(i) + 1) * (x - KM_updated.cluster_centers_(i))
KM = KMeans(n_clusters=3, random_state = 200, init = Updated_centroids(i), n_init = 1)
是的,这是一个可能的解决方案。但是,您可以按照此 pseudo-code 进一步改进您的实施(有关更多信息,请查看此 post Online k-means clustering):
Make initial guesses for the means m1, m2, ..., mk
Set the counts n1, n2, ..., nk to zero
Until interrupted
Acquire the next example, x
If mi is closest to x
Increment ni
Replace mi by mi + (1/ni)*( x - mi)
end_if
end_until
按照这个版本的在线算法,你只需要记住每个簇的均值和分配给簇的数据点数。更新这两个变量后,您可以忘记新数据点。
与您的相比,在此解决方案中您不需要保留过去的数据,因此计算效率更高。
Scikit Learn 中没有这种确切的实现。最接近的实现可能是使用 partial_fit 方法的 MiniBatchKMeans 估计器。
我可以使用之前 Kmeans 拟合的 cluster_center 坐标作为初始参数,以便在新数据到达时按顺序更新 cluster_center 坐标吗?这种方法有什么缺点吗?
已更新在线版 Scikit 学习 K-means:
KM = KMeans(n_clusters=3, random_state = 200, n_init = 1)
ni = 0
Until interrupted:
for x in data:
KM_updated = KM.fit(x)
Updated_centroids(i) = KM_updated.cluster_centers_(i) + 1/len(KM_updated.labels_(i) + 1) * (x - KM_updated.cluster_centers_(i))
KM = KMeans(n_clusters=3, random_state = 200, init = Updated_centroids(i), n_init = 1)
是的,这是一个可能的解决方案。但是,您可以按照此 pseudo-code 进一步改进您的实施(有关更多信息,请查看此 post Online k-means clustering):
Make initial guesses for the means m1, m2, ..., mk
Set the counts n1, n2, ..., nk to zero
Until interrupted
Acquire the next example, x
If mi is closest to x
Increment ni
Replace mi by mi + (1/ni)*( x - mi)
end_if
end_until
按照这个版本的在线算法,你只需要记住每个簇的均值和分配给簇的数据点数。更新这两个变量后,您可以忘记新数据点。
与您的相比,在此解决方案中您不需要保留过去的数据,因此计算效率更高。
Scikit Learn 中没有这种确切的实现。最接近的实现可能是使用 partial_fit 方法的 MiniBatchKMeans 估计器。