3
例如,我有9个变量和362个案例。我做了PCA计算,发现前3个PCA坐标对我来说已经足够了。如何将新点投影到PCA新的基础上?
现在,我在我的9维结构中有了新的观点,并且我想将它投影到主成分系统坐标上。如何获得新的坐标?
%# here is data (362x9)
load SomeData
[W, Y] = pca(data, 'VariableWeights', 'variance', 'Centered', true);
%# orthonormal coefficient matrix
W = diag(std(data))\W;
% Getting mean and weights of data (for future data)
[data, mu, sigma] = zscore(data);
sigma(sigma==0) = 1;
%# New point in original 9dim system
%# For example, it is the first point of our input data
x = data(1,:);
x = bsxfun(@minus,x, mu);
x = bsxfun(@rdivide, x, sigma);
%# New coordinates as principal components
y0 = Y(1,:); %# point we should get in result
y = (W*x')'; %# our result
%# error
sum(abs(y0 - y)) %# 142 => they are not the same point
%# plot
figure()
plot(y0,'g'); hold on;
plot(y,'r');
如何获得新的点的坐标投影到新的主成分的基础?
你有什么'pca()'函数的文档?通常在matlab中,我使用'princomp()'。 – Isaac
'Y(1,:)'和'y'在同一个方向吗? – Isaac
现在,我正在尝试新版本的Matlab。有函数'princomp()'被路由到'pca()'。好吧,我会尝试旧版本,所以我需要它在旧的Matlab –