How to switch order of clusters in silhouette plot?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alex Gimeno
le 2 Fév 2021
Réponse apportée : Walter Roberson
le 14 Fév 2021
I am showing silhouette plots for various k-means implementations in a presentation, and the data tend to separate into two clusters: a smaller one and a larger one. I will be comparing the plots on the same page, so I would like the smaller cluster to always be on the top of the plor, and the larger one on the bottom; however, this is determined by cluster 1 and 2 in the data, which is assigned arbitrarily. Is there an easy way with code to switch which cluster is "on top" in a silhouette plot?
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Fév 2021
rng('default') % For reproducibility
X = [randn(10,2)+3;randn(10,2)-3];
scatter(X(:,1),X(:,2));
title('Randomly Generated Data');
clust = kmeans(X,2);
subplot(2,1,1)
silhouette(X,clust)
subplot(2,1,2)
silhouette(X,3-clust)
You can see that the clusters switched position on the plot.
((Maximum+1) - current) has the effect of reversing the order of clusters
You can play other tricks such as 1, 2, 3 -> 2, 3, 1 by using mod(current,3)+1
0 commentaires
Plus de réponses (1)
darova
le 14 Fév 2021
what about this?
x = rand(20,1);
y = rand(20,1);
plot(x(1:15),y(1:15),'.r')
hold on
plot(x(5:end),y(5:end),'ob')
hold off
0 commentaires
Voir également
Catégories
En savoir plus sur Cluster Analysis and Anomaly Detection 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!