简体   繁体   English

Sklearn Kmeans参数混乱?

[英]Sklearn Kmeans parameter confusion?

So I can run sklearn kmeans as the following: 所以我可以运行sklearn kmeans如下:

kmeans = KMeans(n_clusters=3,init='random',n_init=10,max_iter=500)

But I'm a little confused on what the parameters mean 但我对参数的含义有点困惑

so n_init says: 所以n_init说:

Number of time the k-means algorithm will be run with different centroid seeds. 使用不同质心种子运行k-means算法的时间。 The final results will be the best output of n_init consecutive runs in terms of inertia. 在惯性方面,最终结果将是n_init连续运行的最佳输出。

and max_iter says: max_iter说:

Maximum number of iterations of the k-means algorithm for a single run. 单次运行的k-means算法的最大迭代次数。

But I don't completely understand what that means. 但我不完全明白这意味着什么。 Is n_init the number of times the centroids are moved closer to the points mean, given an initial set of centroids? 在给定初始质心集的情况下, n_init是质心移近点数的平均值吗?

And is max_iter the number of times the whole algorithm is run with new initial centroids? max_iter是整个算法使用新的初始质心运行的次数吗?

So for example, with max_iter=2 , n_init=15 , kmeans will choose initial centroids, then move those centroids 15 times and come up with a clustering result. 因此,例如,使用max_iter=2n_init=15 ,kmeans将选择初始质心,然后将这些质心移动15次并得出聚类结果。 Then kmeans will choose initial centroids again, move those centroids 15 times, and stop. 然后kmeans将再次选择初始质心,移动那些质心15次,然后停止。 Then, it will pick the best clutering out of the two runs? 然后,它将从两次运行中挑选最好的clutering?

Thanks for the help! 谢谢您的帮助!

[Edit] Or is the the exact opposite of what I have here... ? [编辑]或者与我在这里完全相反......?

With max_iter=2 and n_init=15 , kmeans will choose initial centroids 15 times and move up to twice on each of the 15 runs. max_iter=2n_init=15 ,kmeans将选择15次初始质心,并在15次运行中每次运动最多两次。

The default values are n_init=10 and max_iter=300 . 默认值为n_init=10max_iter=300 This means the initial centroids will be chosen 10 times, and each run will use up to 300 iterations. 这意味着初始质心将被选择10次,每次运行将使用多达300次迭代。 The best out of those 10 runs will be the final result. 这10次运行中最好的将是最终结果。

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

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