简体   繁体   English

Sklearn K 表示聚类收敛

[英]Sklearn K means Clustering convergence

I am trying to construct clusters out of a set of data using the Kmeans algorithm from SkLearn .我正在尝试使用SkLearn的 Kmeans 算法从一组数据中构建集群。 I want to know how one can determine whether the algorithm actually converged to a solution for one's data.我想知道如何确定算法是否真正收敛到一个数据的解决方案。

We feed in the tol parameter to define the tolerance for convergence but there is also a max_iter parameter that defines the number of iterations the algorithm will do for each run.我们输入tol参数来定义收敛容差,但还有一个max_iter参数定义算法每次运行的迭代次数。 I get that the algorithm may not always converge within the max_iter times of iterations.我知道算法可能并不总是在迭代的max_iter时间内收敛。 So is there any attribute or a function that I can access to know if the algorithm converged before the max_iter iterations ?那么有没有我可以访问的任何属性或函数来知道算法是否在max_iter迭代之前收敛?

You have access to the n_iter_ field of the KMeans class, it gets set after you call fit (or other routines that internally call fit .您可以访问KMeans类的n_iter_字段,它在您调用fit (或其他内部调用fit例程之后设置。

Not your fault for overlooking that, it's not part of the documentation, I just found it by checking the source code ;)忽略这一点不是你的错,它不是文档的一部分,我只是通过检查源代码找到它;)

When I asked the question I was working with the 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.当我问这个问题时,我正在使用类KMeans [ http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html]。这没有任何功能或属性可以让您访问算法每次运行的n_iter Instead we could use the function k_means [ http://scikit-learn.org/stable/modules/generated/sklearn.cluster.k_means.html] instead of the class which has an option that enables returning the best n_iter .相反,我们可以使用函数k_means [ http://scikit-learn.org/stable/modules/generated/sklearn.cluster.k_means.html]而不是具有允许返回最佳n_iter的选项的类。 But this might have its own complications like having to write the predict by oneself etc.,但这可能有其自身的复杂性,例如必须自己编写predict等,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM