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.
0 个评论
回答(1 个)
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?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!