PCAアルゴリズム(Matlab実装)
701 ワード
コード:
function [newX,T,meanValue] = pca_row(X,CRate)
%
%newX
%T
%meanValue X , newX X
%CRate
%
meanValue=ones(size(X,1),1)*mean(X);
X=X-meanValue;%
C=cov(x);%
% V, D
[V,D]=eig(C);
%
[dummy,order]=sort(diag(D),'descend');
V=V(:,order);%
d=diag(D);% ,
newd=d(order);%
% n ,
sumd=sum(newd);%
for j=1:length(newd)
i=sum(newd(1:j,1))/sumd;% , = n /
if i>CRate% 95% ,
cols=j;
break;
end
end
T=V(:,1:cols);% cols , T
newX=X*T;% T X
end