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

59 visualizaciones (últimos 30 días)
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);

Respuestas (1)

Vineet Joshi
Vineet Joshi el 22 de Abr. de 2021
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.

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by