2014-01-13 29 views
0

,我們有以下命令來分析虹膜數據情節主要成分

load fisheriris 
gscatter(meas(:,1), meas(:,2), species,'rgb'); hold on 
gscatter(meas(:,3), meas(:,4), species,'rgb');hold on 
xlabel('Sepal length'); 
ylabel('Sepal width'); 


[pc,score,latent,tsquare] = princomp(meas); 
pc,latent 
cumsum(latent)./sum(latent) 

,我們得到結果

pc = 

    0.3614 0.6566 -0.5820 0.3155 
    -0.0845 0.7302 0.5979 -0.3197 
    0.8567 -0.1734 0.0762 -0.4798 
    0.3583 -0.0755 0.5458 0.7537 


latent = 

    4.2282 
    0.2427 
    0.0782 
    0.0238 


ans = 

    0.9246 
    0.9777 
    0.9948 
    1.0000 

,我們也推測

enter image description here

我們任務是

請通過繪製前兩個主成分的計劃中關於三個類別的三種顏色的數據投影來顯示。

我們可以通過

x=pc(:,1); 
y=pc(:,2); 

先打電話雙組份但什麼陰謀,請幫我

回答

5

的預計數據到在score變量返回的主成分,因此劇情根本?

gscatter(score(:,1), score(:,2), species, [], [], [], 'on', 'PC1', 'PC2') 
title('Projected Iris data'), grid on 
使用當然你可以 perform the PCA yourself

要麼EIGSVD

X = meas; 
X = bsxfun(@minus, X, mean(X)); % zero-centered data 
[~,S,V] = svd(X,0);    % singular value decomposition 

[S,ord] = sort(diag(S), 'descend'); 
pc = V(:,ord);     % principle components 
latent = S.^2 ./ (size(X,1)-1) % variance explained 
score = X*pc;      % projected data 

projected_data

+0

所以它滿足這些條件嗎?請通過繪製前兩個主成分的計劃中關於三個類別的三種顏色的數據投影來顯示。 –

+0

@datodatuashvili:是的 – Amro

+0

非常感謝你 –