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

1 次查看(过去 30 天)
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.

回答(1 个)

Image Analyst
Image Analyst 2021-9-22
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!

Translated by