3

たとえば、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');

ここに画像の説明を入力してください

新しい主成分ベースに投影された新しいポイントの座標を取得するにはどうすればよいですか?

4

1 に答える 1

8

主な誤謬は、ポイントを新しい基準に変換する操作でした。

y = (W*x')';

ウィキペディアによると:

射影されたベクトルは行列の列です

Y = W*·Z, 

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

しかし、サイズとサイズのpca()リターンWL×MYNxL

したがって、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
于 2012-11-09T10:37:36.360 に答える