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

63 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Dimensionality 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