Search code examples
matlabmachine-learningdata-miningprojectionpca

How to find projection matrix for PCA in MATLAB?


I'm trying to reduce the dimensionality of my data with PCA.

So I call [COEFF, SCORE] = princomp(data); According to this answer, I can reconstruct my data with SCORE * COEFF' + Mean, and it works.

But I'm trying to find the projection matrix P, where any given vector x can be transformed to its projection in PCA space.

My intuition tells me that I should be able to project x by :

proj = ((x-m) * inv(C)) + m

where m is the mean of my data.

so I test this by choosing x as the first observation of my data, and I expect proj should be very close to the first row of SCORE. However this is not the case.

So where am I doing wrong? And how can I find the projection matrix?

Thanks for any help!


Solution

  • Oops, now I see my mistake.

    First of all, COEFF is orthogonal (not sure) so inv(COEFF) == COEFF'

    and the projection is found by

    proj = COEFF' * (x-m)