how apply k-means on a n by m matrix based on rows

8 views (last 30 days)
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.

Answers (1)

Image Analyst
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?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!