MATLAB: Calculate PCA score from coefficient and original data

coefpcascore

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?

Best Answer

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