I need to know each point to which cluster in kmeans fun.

3 views (last 30 days)
hi, i used this function kmeans, and take simple example
x=[100 2 4 10 200; 50 100 20 1 5];
[p o]=kmeans(x,2)
what i got:
p =
1
2
o =
100 2 4 10 200
50 100 20 1 5
what i need is know each point for which cluster belong, what the code do is just get the two clusters i gave it and the points that i gave it.
how I know the clusters that each point belong to?
thanks
  2 Comments
huda nawaf
huda nawaf on 1 Aug 2012
to be more clear, if I have array : x=[100 2 4 10 200; 50 100 20 1 5; 3 4 5 6 6;....]; this array show the rate of similarity. where the first row show the similarity rate between user1 and the all other four users, the second row show the rate of similarity between second user and the others and so on. how I know each user for which cluster belong?
thanks

Sign in to comment.

Accepted Answer

Peter Perkins
Peter Perkins on 1 Aug 2012
Huda, you gave kmeans two points and asked it to cluster them into two clusters. It has assigned the first point to cluster 1, whose centroid is at the first point, and similarly for the second point. Presumably that is not very informative.
I don't know what your data mean, or whether kmeans makes sense, but your description sounds like something more suited to distance-based methods such as hierarchical clustering or multidimensional scaling, both of which are available in the Statistics Toolbox. You would, of course, have to convert your similarities to dissimilarities.
  2 Comments
huda nawaf
huda nawaf on 2 Aug 2012
Edited: Walter Roberson on 2 Aug 2012
thanks,
i used statistic toolbox
X = [0 4 6;2 0 4;3 5 0);
each row represent rates of similarity of one user with the other, what i need is clustering of users
x=magic(3);
c = clusterdata(X,'linkage','ward','savememory','on',...
'maxclust',4);
scatter3(X(:,1),X(:,2),X(:,3),10,c)
still ,there is something is not clear, how I know the cluster of each user?
Walter Roberson
Walter Roberson on 2 Aug 2012
The output of clusterdata is the cluster number for each sample.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 2 Aug 2012
The first output from kmeans() is the cluster number for each sample.
IDX = kmeans(X,k) partitions the points in the n-by-p data matrix X into k clusters. This iterative partitioning minimizes the sum, over all clusters, of the within-cluster sums of point-to-cluster-centroid distances. Rows of X correspond to points, columns correspond to variables. kmeans returns an n-by-1 vector IDX containing the cluster indices of each point. By default, kmeans uses squared Euclidean distances. When X is a vector, kmeans treats it as an n-by-1 data matrix, regardless of its orientation.
  7 Comments
huda nawaf
huda nawaf on 6 Aug 2012
sorry , may be im not clear. I;m also do not mean the no. of clusters. what I mean , I thought that user1 belong to second cluster, user2 belong to third cluster, and user3 belong to second cluster depending on least distance. where each row represet the rate of similarity with other users.
in this case , is clusterdata suitable way for clustering? thanks
Peter Perkins
Peter Perkins on 6 Aug 2012
Walter, huda is using hirarchical clustering now, not k-means, so I think he was responding to my earlier post.
huda, again, you have given clusterdata three points,andf asked for three clusters, and it has returned what you asked for. The cluster number is completely arbitrary. I suspect that if you used linkage, then dendrogram, you'd see what you were expecting
d = [0 10 20; 10 0 5; 20 5 0] % d is a distance matrix
z = linkage(squareform(d)) % convert d to vector form first
dendrogram(z)
The dendrogram plot has labels on its horizontal axis that refer to the original points, not the cluster numbers).

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!