简体   繁体   English

sklearn 中可重现的 kmeans

[英]Reproducible kmeans in sklearn

I am using the document clustering code available here .我正在使用此处提供的文档聚类代码。 I know that k-means is solving a non-convex problem and hence the results of optimization will differ every time I run it, but is there a way to make the clustering reproducible (maybe by fixing some random seed)?我知道 k-means 正在解决一个非凸问题,因此每次运行时优化的结果都会有所不同,但是有没有办法使聚类可重现(也许通过修复一些随机种子)?

You can fix the random_state parameter of K-means .您可以修复K-meansrandom_state参数。 In the following code I use 42:在下面的代码中,我使用了 42:

km = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1, 
                               verbose=opts.verbose,
                               random_state = 42)

You can check the documentation here .您可以在此处查看文档。

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

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