Calculate PCA score from coefficient and original data

21 views (last 30 days)
Hi all,
I want to do cross validation of a non-linear regression on principal components as input. Therefore, I do PCA on my training set, and use the regression coefficient to transform the standardized test set into their principal components. However in the following I found pc score!=zscore(data)*coef. Appreciate if anyone can explain to me. Thanks alot.
[coef2, score2, latent2, explained2, mu2] = pca(data_raw_ccc(:,2:end));
zdata=zscore(data_raw_ccc(:,2:end));
score3=zdata*coef2;
diff=score3-score2; % NOT EQUAL 0, WHY?

Accepted Answer

the cyclist
the cyclist on 10 Apr 2015
Edited: the cyclist on 10 Apr 2015
By default, pca centers the data around the mean, but does not scale it to unit variance.
The original data can be reconstructed by
score2*coef2
  5 Comments
Shawn Miller
Shawn Miller on 4 May 2016
I think you are saying score2*coef2' or score2*inv(coef2)?@the cyclist
the cyclist
the cyclist on 26 Dec 2020
Four years after-the-fact, I have seen this reply. Yes, you are correct. It should be
score2*coef2'
:-)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!