The number of rows in X must match the length of CLUST
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I did the following:
I=imread('image.png');
I2=im2double(I);
I3=I2(:);
cidx = fcm(I3,5);
But, when I run the following command:
silhouette(I3,cidx)
I get the following error:
Error using silhouette (line 82) The number of rows in X must match the length of CLUST. How can I fix that?
Thanks.
0 commentaires
Réponses (3)
Wayne King
le 31 Déc 2013
Modifié(e) : Wayne King
le 31 Déc 2013
rng default;
X = [randn(10,2)+2*ones(10,2); randn(10,2)-2*ones(10,2)];
[Cntr,U] = fcm(X,2);
Cluster centers are
Cntr
-1.6498 -2.4173
2.7346 2.7327
Now look at the cluster membership for the first ten rows of X
U(:,1:10)
clearly X(1,:) belongs to cluster 2 because 0.8603 is much larger than 0.1397, X(2,:) even more so because 0.9293 is close to 1. So you would create an idx vector with a 2 for the first row of X and a 2 for the second row of X. You would continue on in that way.
If you look at:
U(:,11)
0.9454
0.0546
that means that X(11,:) belongs to cluster 1.
As the documentation clearly explains the closer the value to 0 the more unlike that cluster an observation is, the closer to 1 the more like it.
You have five clusters so you are going to have five rows in U, pick the largest value in those rows as the cluster. But of course, you might not have something clearly belonging to one cluster.
Ultimately you want to use the information in U to create a vector with the same number of rows as your input with a 1,2,3,4, or 5 as the element which indicates cluster membership.
To form the cluster membership vector, you can do something like:
X = [randn(10,2)+2*ones(10,2); randn(10,2)-2*ones(10,2)];
[Cntr,U] = fcm(X,2);
[Y,cidx] = max(U,[],1);
cidx = cidx';
Thank you for accepting my answer if I have helped you.
2 commentaires
Wayne King
le 31 Déc 2013
I've shown you exactly how to do it for 2 clusters above, so just change to 5 above. But you have to keep in mind that taking the maximum doesn't mean that these elements are going to be clear members of one cluster or another.
For example:
0.12 0.14 0.13 0.11 0.10
0.14 is the maximum so that would be cluster 2, but there's not a clear winner.
Wayne King
le 31 Déc 2013
Modifié(e) : Wayne King
le 31 Déc 2013
You have to tell us what the lengths of I3 and cidx are.
The number of rows in I3 has to match the number of rows in cidx.
The first output of fcm() (the one you are using here) is not going to give a length that is equal to the length of the input. That just gives you the cluster centers.
You would have to come up with a vector of cluster memberships for each row in I3 based on the output of fcm() -- you could use the optional output U to assign a cluster membership to each row of I3.
1 commentaire
Wayne King
le 31 Déc 2013
No, did you read my answer? Use the optional output, U, from fcm() and then you'll have to assign cluster membership based on grade of membership -- from the help for fcm()
"The membership function matrix U contains the grade of membership of each DATA point in each cluster. The values 0 and 1 indicate no membership and full membership respectively. Grades between 0 and 1 indicate that the data point has partial membership in a cluster."
Voir également
Catégories
En savoir plus sur Data Clustering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!