Support new exit conditions in cluster.vq.kmeans/kmeans2
Hi all, I'm going through the source code of `cluster` package recently. I noticed that the only exit conditions supported by `kmeans` function is whether the "average distance from observations to the corresponding centroids" stop decreasing (or decrease slowly enough) or not controlled by the `thresh` parameter. However, it is not guaranteed that this value will decrease on every iteration especially in some extreme conditions. The iteration may exit prematurely. A more reliable criteria is the "average/total movement of the centroids" between two successive iterations. This is also what scikit-learn uses in its k-means module.[1] Besides, I found another available convergence condition on Wikipedia[2]:
The algorithm has converged when the assignments no longer change. (i.e. converge when the result of `vq` no longer changes.) Maybe we can consider adding these two exit conditions to the `kmeans` and `kmeans2` function?
Cheers, Richard [1] https://github.com/scikit-learn/scikit-learn/blob/b53b573c31b60a2caa054a6720... [2] http://en.wikipedia.org/wiki/K-means
participants (1)
-
Richard Tsai