Saturday, February 10, 2007

Principal component analysis

Principal component analysis (PCA) involves a mathematical procedure that transforms a number of (possibly) correlated variables into a (smaller) number of uncorrelated variables called principal components. The first principal component accounts for as much of the variability in the data as possible, and each succeeding component accounts for as much of the remaining variability as possible.
Objectives of principal component analysis:1)To discover or to reduce the dimensionality of the data set. 2)To identify new meaningful underlying variables. Matlab code of PCA:

function [patterns, targets, UW, m, W] = PCA(patterns, targets, dimension)
[r,c] = size(patterns);
if (r < dimension)dimension = r;end
%Calculate cov matrix and the PCA matrixes m = mean(patterns')';S = ((patterns - m*ones(1,c)) * (patterns - m*ones(1,c))');[V, D] = eig(S);W = V(:,r-dimension+1:r)';U = S*W'*inv(W*S*W');
%Calculate new patternsUW = U*W;patterns = W*patterns;

No comments: