Why Kmeans function give us give different answer?
2 次查看(过去 30 天)
显示 更早的评论
采纳的回答
José-Luis
2014-9-22
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.
2 个评论
Adam Filion
2014-9-22
Try using the 'replicates' option for kmeans to automatically run the algorithm multiple times and return the best answer:
>> doc kmeans
You can set the order of random numbers generated with the rng command:
>> doc rng
Putting something like rng(3) before kmeans will make the results repeatable even though it involves random starting points.
更多回答(1 个)
Image Analyst
2014-9-22
Like many other types of numerical minimizations, the solution that kmeans reaches often depends on the starting points. It is possible for kmeans to reach a local minimum, where reassigning any one point to a new cluster would increase the total sum of point-to-centroid distances, but where a better solution does exist. However, you can use the optional 'replicates' parameter to overcome that problem.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!