how apply k-means on a n by m matrix based on rows
1 view (last 30 days)
Show older comments
I want to apply a kmeans clustering with cosine distance on a n by m matrix and I want to define each row as a sample. how can I do that?
For example, I have a 30x50 matrix and I want to cluster them based on cosine similarity of each of the rows. Means that I have 50 samples. Consider each row as an image that I want to cluster them based on cosine similarity.
0 Comments
Answers (1)
Image Analyst
on 22 Sep 2021
So you have 30 images, and for each image there are 50 measurements/features/samples or whatever you want to call the data. So why can't you just call kmeans
numClusters = 4; % Whatever you want.
[indexes, clusterCentroids] = kmeans(data, numClusters, 'distance', 'cosine');
Why do you want that distance metric (cosine) instead of any of the other, more common, distance metrics?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!