Tuesday, February 16, 2016

PCA in matlab

Here is a great introduction to PCA for beginners and I can't do better than this Princeton PCA

After reading this I was a bit confused on how to apply this in my matlab code. Let's go through it

    
    [eigenvectors,score,latent] = pca(md);
    md = md * eigenvectors(:,1:10);
    fprintf('Eigenvalues for the data \n');
    disp(latent);

Here md contains my data, suppose that is a matrix of size 10000 x 15 . Now generally I should do some analysis on the variances of eigenvectors before selecting the final dimension that I want. But let's just say that I want 10 .

eigenvectors is a 15 x 15 matrix whose columns are my eigenvectors. Now I project my original data onto the space given by this and get the reduced matrix in md.