Sklearn K表示Clustering convergence

Sklearn K means Clustering convergence

我正在尝试使用 SkLearn 中的 Kmeans 算法从一组数据中构造聚类。我想知道如何确定算法是否真正收敛到一个数据的解决方案。

我们输入 tol 参数来定义收敛容差,但还有一个 max_iter 参数定义算法将为每个 运行 执行的迭代次数。我知道该算法可能并不总是在 max_iter 次迭代内收敛。那么有没有我可以访问的属性或函数来了解算法是否在 max_iter 次迭代之前收敛?

当我问这个问题时,我正在使用 class KMeans [http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html].This does not have any function or attribute that allows you to access the n_iter of each run of the algorithm. Instead we could use the function k_means [http://scikit-learn.org/stable/modules/generated/sklearn.cluster.k_means.html] 而不是 class,它有一个选项可以返回最好的 n_iter。但这可能有其自身的复杂性,例如必须自己编写 predict 等,

您可以访问 KMeans class 的 n_iter_ 字段,它会在您调用 fit(或其他内部调用 [=12 的例程)后设置=].

这不是你的错,它不是文档的一部分,我只是通过检查源代码发现的;)