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

조회 수: 82 (최근 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 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