how can i convert Principal component analysis(PCA) data back to original data ?

73 ビュー (過去 30 日間)
NN
NN 2021 年 4 月 7 日
回答済み: Vineet Joshi 2021 年 4 月 22 日
Hi all,
i used the below code to reduce dimension suing PCA in steps, and how can i convert the output back to original data scale?Kindly help with the code
z=zscore(XTrain);
M=cov(z) ;
[V,D]=eig(M);
d=diag(D);
eig1=sort(d,'descend');
v=fliplr(V) ;
S=0;
i=0;
while S/sum(eig1)<0.85
i=i+1;
S=S+eig1(i);
end
NEWXTrain=z*v(:,1:i);

回答 (1 件)

Vineet Joshi
Vineet Joshi 2021 年 4 月 22 日
Hi
PCA works by projecting a higher dimensional data to a lower dimension so it is not possible to reconstruct the exact original data from the lower dimensional representation.
None the less, you can get the approximate data back using the following equation.
Approx. Data = Projected Data x Coefficients’ + Mean
Refer to the following MATLAB code for an example
%Load data
load hald
size(ingredients)
ans =
13 4
%Reduce data to 3 dimensions from 4.
[coeff,score,latent,tsquared,explained,mu]=pca(ingredients,'NumComponents',3);
size(score)
ans =
13 3
%Reconstruct the original data back (approximate).
ingredients_hat = score * coeff' + mu;
size(ingredients_hat)
ans =
13 4
You can refer to the documentation page for help with pca function.
Hope this helps.

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by