Kmeans plot centroid error
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to cluster my two-dimensional data with k-means clustering, where my data is wv_prop (attached) and am plotting according to the example code provided by matlab. However,I am getting a strange result as seen in the attached figure where there are no points around the 2nd centroid. Anyone know why this might be? It looks like the idx variable contains only 1's, and no 2's.
[idx,C] = kmeans(wv_prop,2);
figure;
plot(wv_prop(idx==1,1),wv_prop(idx==1,2),'r.','MarkerSize',12)
hold on
plot(wv_prop(idx==2,1),wv_prop(idx==2,2),'b.','MarkerSize',12)
plot(C(:,1),C(:,2),'kx',...
'MarkerSize',15,'LineWidth',3)
legend('Cluster 1','Cluster 2','Centroids',...
'Location','NW')
title 'Cluster Assignments and Centroids'
hold off
0 comentarios
Respuestas (1)
KSSV
el 28 de Ag. de 2018
Try removing the outliers:
load('wv_prop.mat')
% Remove outliers
idx = abs(wv_prop(:,2) - nanmean(wv_prop(:,2))) > 3*nanstd(wv_prop(:,2));
wv_prop(idx,:) = [] ;
[idx,C] = kmeans(wv_prop,2);
figure;
plot(wv_prop(idx==1,1),wv_prop(idx==1,2),'r.','MarkerSize',12)
hold on
plot(wv_prop(idx==2,1),wv_prop(idx==2,2),'b.','MarkerSize',12)
plot(C(:,1),C(:,2),'kx',...
'MarkerSize',15,'LineWidth',3)
legend('Cluster 1','Cluster 2','Centroids',...
'Location','NW')
title 'Cluster Assignments and Centroids'
hold off
0 comentarios
Ver también
Categorías
Más información sobre Cluster Analysis and Anomaly Detection en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!