I'm attempting to use PCA to reduce the dimensionality of a dataset I have. I want to explain 99% of the variance in the dataset, and I think I've been able to determine that, but I'm unsure what I have to do to my original dataset to reduce the dimensions. Here's what I've got so far (MATLAB code):
rng 'default' M = 1000; % Number of observations N = 500; % Number of variables observed X = rand(M,N); % Remove mean. X = (X - repmat(mean(X),[size(X,1) 1])); % Determine the eigenvector (V) and eigenvalues (D) of the covariance of % the matrix X. [V, D] = eig(cov(X)); % Calculate variance of the vectors (largest to smallest). var_vec = flipud(diag(D)); % Calculate the cumulative percentage of the variances. percentages = cumsum(var_vec) / sum(diag(D)); % Find the 99% variance PC99 = find(percentages >= 0.99, 1);
PC99 tells me the that components 1 to 464 (out of 500) contain 99% of the variance, which I believe to be correct, but I'm now unsure on how to manipulate my original data in order to reduce the dimension from 1000x500 to 1000x464.
Thanks for any help.