how can i convert Principal component analysis(PCA) data back to original data ?
38 次查看(过去 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);
0 个评论
回答(1 个)
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
Hope this helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!