2013-08-06 81 views
1

我有一個510x6的數據矩陣,並希望對此進行K均值聚類分析。我在繪製2維的所有不同集羣時遇到了問題。是不是可以在兩個維度上繪製6個不同的集羣?K均值聚類圖

回答

8

讓我們先看看150x4的一些數據,然後嘗試將其拆分爲6個不同的集羣。該fisheriris數據集有四列(你的具有6),其對應於萼片長度,萼片寬度,花瓣長度和花瓣寬度,並且可以被加載到MATLAB這樣的:

load fisheriris 

然後,我們可以把數據分解成六組有:

clusters = kmeans(meas, 6); 

cluster1 = meas(clusters == 1, :); 
cluster2 = meas(clusters == 2, :); 
cluster3 = meas(clusters == 3, :); 
cluster4 = meas(clusters == 4, :); 
cluster5 = meas(clusters == 5, :); 
cluster6 = meas(clusters == 6, :); 

既然我們有四塊每個數據點的信息,以顯現每次我們需要選擇我們想看看集羣。例如,我可能想看看針對萼片寬度的萼片長度的簇。這是前兩列,我可以看到他們:

figure 
axes 

plot(cluster1(:, [1, 2]), '*'); hold all 
plot(cluster2(:, [1, 2]), '*') 
plot(cluster3(:, [1, 2]), '*') 
plot(cluster4(:, [1, 2]), '*') 
plot(cluster5(:, [1, 2]), '*') 
plot(cluster6(:, [1, 2]), '*') 

xlabel('Sepal Length') 
ylabel('Sepal Width') 

enter image description here

如果我想看看在一次列,我們需要去建立一個維度:

figure 
axes 
hold all 

plot3(cluster1(:, 1), cluster1(:, 2), cluster1(:, 3),'*') 
plot3(cluster2(:, 1), cluster2(:, 2), cluster2(:, 3),'*') 
plot3(cluster3(:, 1), cluster3(:, 2), cluster3(:, 3),'*') 
plot3(cluster4(:, 1), cluster4(:, 2), cluster4(:, 3),'*') 
plot3(cluster5(:, 1), cluster5(:, 2), cluster5(:, 3),'*') 
plot3(cluster6(:, 1), cluster6(:, 2), cluster6(:, 3),'*') 

grid on 
box on 

enter image description here

您的數據有六個維度,因此更難以直觀地瞭解羣集。

plotmatrix(meas) 

enter image description here

+1

+1的詳細信息:你可以在做類似plotmatrix功能的東西一展身手! – Schorsch