MATLAB: Kmeans function give us give different answer

clusteringk-meanskmeansStatistics and Machine Learning Toolbox

I have noticed that kmeans function for one k value in a single run gives different cluster indices than while using in a loop with varying k say from 2:N. I do not understand this. It will be great if it is clear to me.

Best Answer

Because, if you are using the default settings, kmeans() randomly selects a starting point. The algorithm is not deterministic and the results might depend on that starting position.