Query regarding k-means clustering in MATLAB

筅森魡賤 提交于 2019-11-27 09:06:00

问题


I have a very large amount of data in the form of matrix.I have already clustered it using k-means clustering in MATLAB R2013a. I want the exact coordinates of the centroid of each cluster formed.. Is it possible using any formula or anything else?

I want to find out the centroid of each cluster so that whenever some new data arrives in matrix, i can compute its distance from each centroid so as to find out the cluster to which new data will belong

My data is heterogeneous in nature.So,its difficult to find out average of data of each cluster.So, i am trying to write some code for printing the centroid location automatically.


回答1:


In MATLAB, use

[idx,C] = kmeans(..) 

instead of

idx = kmeans(..) 

As per the documentation:

[idx,C] = kmeans(..) returns the k cluster centroid locations in the k-by-p matrix C.




回答2:


The centroid is simply evaluated as the average value of all the points' coordinates that are assigned to that cluster.

If you have the assignments {point;cluster} you can easily evaluate the centroid: let's say you have a given cluster with n points assigned to it and these points are a1,a2,...,an. You can evaluate the centroid for such cluster by using:

centroid=(a1+a2+...+an)/n

Obviously you can run this process in a loop, depending on how your data structure (i.e. the assignment point/centroid) is organized.



来源:https://stackoverflow.com/questions/35359104/query-regarding-k-means-clustering-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!