【问题标题】:How to project a new point to PCA new basis?如何将新点投射到 PCA 新基础上?
【发布时间】: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


【解决方案1】:

主要的谬误在于将点转换为新的基础:

y = (W*x')';

维基百科说:

投影向量是矩阵的列

Y = W*·Z, 

Y is L×N, W is M×L, Z is M×N,

但是pca() 返回大小为L×MW 和大小为YNxL

所以,Matlab 中的正确方程是:

y = x*W

以下是更正后的代码:

[W, Y] = pca(data, 'VariableWeights', 'variance', 'Centered', true);
W = diag(std(data))\W;

%# Getting mean and weights of data (for future data)
[~, mu, we] = zscore(data);
we(we==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, we);

%# New coordinates as principal components
y = x*W;
y0 = Y(1,:);
sum(abs(y0 - y)) %# 4.1883e-14 ~= 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 2021-01-11
    • 1970-01-01
    • 2020-11-16
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多