例如,我有9个变量和362个案例。我进行了PCA计算,并发现前3个PCA坐标对我来说足够了。
现在,我有一个新的点在我的9维结构中,我想将它投影到主成分系统坐标上。如何获得它的新坐标?
如何获取投影到新主成分基的新点的坐标?
现在,我有一个新的点在我的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()
。 - IsaacY(1,:)
和y
是否朝着同一个方向? - Isaacprincomp()
被路由到了pca()
。好的,我会尝试在旧版本中运行它,更何况我需要让它在旧版的Matlab中工作。 - Larry FoobarY(1,:)
和y
都是1x9
。 - Larry FoobarY(1,:)
是否近似为y
的倍数? - Isaac