2

I am trying to perform a dimension reduction using pca in Matlab. From this code below, I get coefficient, score, latent, and t-squared. However, it is still fuzzy to me how to reduce the actual dimension from pc analysis. What I want to do is to reduce the number of column (which is 3 originally in this case) to 1 or 2. Can you please tell me how to do it?

matrix = [ 1 2 3; 4 3 2; 1 3 5; 4 2 3; 1 2 3; 2 1 3];
[coeff, score, latent, tsquared] = pca(matrix);

1 Answers1

3

coeff is your principal components matrix, simply truncate it by removing as many columns (from the end!) as you wish. In other words - in order to project to 1 dimension take first column of coeff and multiply by it your data. If you want to project to 2 dimensions - take two first columns and multiply. Your data is N x d, coeff is d x d, thus if you limit coeff to 2 columns you get

  X     coeff_truncated  =  projected_data
N x d      d x 2               N x 2

as desired.

lejlot
  • 64,777
  • 8
  • 131
  • 164