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

4 次查看(过去 30 天)
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 个评论
huda nawaf
huda nawaf 2012-8-1
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

请先登录,再进行评论。

采纳的回答

Peter Perkins
Peter Perkins 2012-8-1
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 个评论
huda nawaf
huda nawaf 2012-8-2
编辑:Walter Roberson 2012-8-2
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 2012-8-2
The output of clusterdata is the cluster number for each sample.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-8-2
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 个评论
huda nawaf
huda nawaf 2012-8-6
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 2012-8-6
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).

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by