Stop condition
For the k-means algorithm, the default stop condition is when there is no more shifting of cluster centers in step 5. But as with many other algorithms, k-means algorithms may take lot of time to converge, especially while processing large datasets in a high-dimensional problem space. Instead of waiting for the algorithm to converge, we can also explicitly define the stop condition as follows:
- By specifying the maximum execution time:
- Stop condition: t>tmax, where t is the current execution time and tmax is the maximum execution time we have set for the algorithm.
- By specifying the maximum iterations:
- Stop condition: if m>mmax, where m is the current iteration and mmax is the maximum number of iterations we have set for the algorithm.