MATLAB: K-means without iteration

clusteringhierarchical algorithmk-means

Hello,
My problem is that it is difficult to get the optimal cluster number by using k-means, so I thought of using a hierarchical algorithm to find the optimal cluster number. After defining my ideal classification I want to use this classification to find the centroids with k-means, without iteration.
if true
data= rand(300,5);
D = pdist(data);
Z = linkage(D,'ward');
T = cluster(Z,'maxclust',6);
end
Now I want to use the clusters defined in vector T and the positions in to k-means algorithm without iterations. Can anyone give a tip how to do?
Thank you.

Best Answer

  • Not sure I follow exactly, but you could use grpstats to compute the coordinatewise means of data for each distinct value of T. You could use pdist2 to compute the distance from each data point to each centroid. You could use min to figure out which centroid is closest to each point (note the second output of the min command).