Skip to main content
. Author manuscript; available in PMC: 2021 Nov 10.
Published in final edited form as: Stat Interface. 2019 Mar 11;12(2):283–293. doi: 10.4310/sii.2019.v12.n2.a9
Algorithm 3 K-means clustering algorithm
1:Generate an initial set ofKcentroidsm1,m2,,mK;2:Alternate between the following two steps3:Assign each pointxto theclosestclusterargminj{1,2,,K}xmj2;4:Calculate the new cluster centroidsmjnew=1SjxSjx,j=1,2,,K;5:Stop when cluster assignment no longer changes.