MATLAB: How to find relevent principal component .

princomp

Hi,
I am trying to do PCA analysis on featurevector size 30×17600, where 30 is the number of images and 17600 is the number of coffecients.
How can I find how many principal componts are requied for corect represtntaion of data.
[M N]=size(feature_vector'); m=mean(feature_vector',2); m_adj = feature_vector' – repmat(double(m),1,N); [evectors, score, evalues] = princomp(feature_vector','econ');
How to find the revelent pricomponent for multiplying with mean adujsted data
feature_vector_final=feature_vector'*evectors;
Please help me.
Thanks in advance

Best Answer

Calculate the quantity:
cumsum(evalues)./sum(evalues)
The will show you the cumulative variance explained by keeping the first n components. You can also look at the following plot (called a scree plot):
xOffset = -0.2;
yOffset = 2;
nComponentsToShow = 5;
figure; hold on;
p(1) = bar(1e2*evalues(1:nComponentsToShow)/sum(evalues));
ylabel('Variance explained (%)');
xlabel('Factor');
set(p(1),'FaceColor','Black');
set(gca,'XTick',1:size(evalues,1));
for i = 1 : nComponentsToShow
text(i+xOffset,1e2*evalues(i)/sum(evalues)+yOffset,sprintf...
('%0.2f%%',1e2*sum(evalues(1:i))/sum(evalues)));
end
Looking at the total variance explained you can decide on how many components to keep.
Conrad