【发布时间】:2012-11-09 06:39:32
【问题描述】:
例如,我有 9 个变量和 362 个案例。我进行了 PCA 计算,发现前 3 个 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()。 -
Y(1,:)和y方向一致吗? -
现在,我正在尝试使用新版本的 Matlab。函数
princomp()被路由到pca()。好的,我会在旧版本中尝试,所以我需要它在旧的 Matlab 中工作 -
@Isaac,是的,
Y(1,:)和y都是1x9。 -
方向,不是维度。
Y(1,:)是y的倍数吗?
标签: matlab pca coordinate-transformation bsxfun