using plot in k-means
10 ビュー (過去 30 日間)
古いコメントを表示
i try to applly k-means using data like this:
x=[ 3.4600 3.8700 3.6100 1.0000 1.0000 2.0000 ]
[ 3.0900 3.3400 3.2200 2.0000 0 1.0000]
[ 3.3300 3.0300 3.1900 1.0000 1.0000 1.0000]
[ 3.5600 3.3400 3.4900 2.0000 2.0000 1.0000]
[ 3.2600 3.1500 3.2000 1.0000 0 0]
[ 3.1900 3.3600 3.3700 1.0000 0 1.0000]
[ 3.1600 3.2100 3.1400 1.0000 1.0000 1.0000]
[ 3.7600 3.6200 3.5800 0 1.0000 1.0000]
[ 3.0900 3.1500 2.9300 1.0000 1.0000 1.0000]
[ 3.6300 3.6900 3.5600 0 0 1.0000]
[ 3.0700 3.0800 2.8600 0 1.0000 1.0000]
and i write this code in matlab
clear;
clc;
x=xlsread('test.xlsx',1,'C3:H159');
k=3;
p=200;
opts = statset('Display','final');
%[idx,ctrs,sumd] = kmeans(x,k,'Distance','city','Replicates',p,'Options',opts,'start','uniform','emptyaction','drop');
[idx,ctrs,sumd] = kmeans(x,k,'Distance','city','Replicates',p,'Options',opts);
plot(x(idx==1,1),x(idx==1,2),'r.','MarkerSize',12)
hold on
plot(x(idx==2,1),x(idx==2,2),'b.','MarkerSize',12)
plot(x(idx==3,1),x(idx==3,2),'g.','MarkerSize',12)
plot(ctrs(:,1),ctrs(:,2),'kx','MarkerSize',12,'LineWidth',2)
plot(ctrs(:,1),ctrs(:,2),'ko','MarkerSize',12,'LineWidth',2)
legend('Cluster 1','Cluster 2','Cluster 3','Centroids','Location','NW');
but results are illustrated using plot function is irregular, in the sense that the object is not clustered with either. any one can help me to improve this code, thanx b4
2 件のコメント
Jing
2013 年 6 月 5 日
What are you trying to do with the PLOT? Show the distribution of your data? If so, you need to first determine which dimensions you want to show the distribution in, because you have 6 dimensions in your data, it's impossible to show them all in one plot without reduce the dimensions.
回答 (3 件)
Jing
2013 年 6 月 9 日
Like I said above, first of all, you need to decide which dimensions you want to show your clusters. You can't show the clusters in 6 dimension. Say, you want to show in the first two dimension, then your code is right for that. The reason you find 'the plot is irregular', may be the first two dimension is far from enough to determine the centroid. To show more dimension in a figure, you may also use plot3 to include 3 dimensions:
dm=[1,2,3];% draw first 3 dimension
plot3(x(idx==1,dm(1)),x(idx==1,dm(2)),x(idx==1,dm(3)),'r.','MarkerSize',12);
hold on;
plot3(x(idx==2,dm(1)),x(idx==2,dm(2)),x(idx==2,dm(3)),'b.','MarkerSize',12);
plot3(x(idx==3,dm(1)),x(idx==3,dm(2)),x(idx==3,dm(3)),'g.','MarkerSize',12);
plot3(ctrs(:,dm(1)),ctrs(:,dm(2)),ctrs(:,dm(3)),'ko','MarkerSize',12,'LineWidth',2);
legend('Cluster 1','Cluster 2','Cluster 3','Centroids');
hold off;
1 件のコメント
Tom Lane
2013 年 6 月 9 日
You may also want to consider the gscatter function for plotting in two dimensions. It just simplifies some code, but it does not deal with the issue that Jing points out.
Kawther
2014 年 11 月 30 日
What if i wanted to plot 4 clusters. should i plot in 4 dimensions? if yes, how can i plot?
0 件のコメント
Kawther
2014 年 11 月 30 日
編集済み: Kawther
2014 年 11 月 30 日
Dear All.
Considering that the clusters represent decision region for each sent symbol, how can i determine the decision region, and how can i find the bet error rate for the clusters resulting from the Kmean?
Thank you Kawther Hamad,
1 件のコメント
Kawther
2014 年 11 月 30 日
Can i consider the originally sent data as a training data and resend data again and consider it and a test data and use them to find the bet error rate?
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!