如何记录 k-means 中每次迭代的质心?
How to keep record of centroids of every iteration in k-means?
通过使用 "kmeans.cluster_centers_" 我得到了每个集群的最终质心,但是如果我想跟踪所有迭代中的所有质心并将结果存储到列表中怎么办。
Scikit-learn 不会为您提供中间结果,也无法通过标准 API 提供中间结果。
获得它们的一种 hacky 方法是使用类似这样的东西:
k_means = KMeans(max_iter=1)
for i in range(300):
k_means.fit(X)
intermediate_centers = k_means.cluster_centers_
k_means = KMeans(max_iter=1, init=intermediate_centers)
这不是一个快速的方法,我不推荐 运行 在生产环境中使用它。
通过使用 "kmeans.cluster_centers_" 我得到了每个集群的最终质心,但是如果我想跟踪所有迭代中的所有质心并将结果存储到列表中怎么办。
Scikit-learn 不会为您提供中间结果,也无法通过标准 API 提供中间结果。 获得它们的一种 hacky 方法是使用类似这样的东西:
k_means = KMeans(max_iter=1)
for i in range(300):
k_means.fit(X)
intermediate_centers = k_means.cluster_centers_
k_means = KMeans(max_iter=1, init=intermediate_centers)
这不是一个快速的方法,我不推荐 运行 在生产环境中使用它。