PCA for a vector such as [100-by-1]
1 view (last 30 days)
Show older comments
Is it reasonable to do a PCA on a vector? I've been using Matlab with this code:
[M,N] = size(A); mn = mean(A);
A = A - repmat(mn,1,N);
B = A'; [u,s,pc] = svd(B);
S_diag = diag(S); V = S_diag .* S_diag;
Aout = PC' * A;
and I got PC is a [100,100] matrix and principal component 1 is Aout(1,1), principal component 2 is Aout(2,1) and so on.
Not sure if this is correct. Please help and Thank you.
2 Comments
Greg Heath
on 4 Nov 2013
I don't understand your terminology "PCA on a vector". You have performed PCA on a matrix, which is correct.
Or am I missing something?
Accepted Answer
Walter Roberson
on 4 Nov 2013
Yup. Consider transposing the vector.
3 Comments
Walter Roberson
on 4 Nov 2013
If you have a vector with 100 elements, it can either be a single observation over 100 variables, or it can be 100 observations over a single variable. V compared to transpose(V) .
Consider if you have a single observation over 100 variables. PCA is to find the variable which accounts for the greatest variance. But if there is only a single observation, then the variance for each variable is 0, so the ordering of components would be whatever decision procedure you use to break ties. The easiest such procedure is to order by original index; with a 100-way tie, that would lead to the ordering being 1:100 .
Note: be sure to explicitly code mean(A,1) or mean(A,2) and not mean(A) : mean(A) when A is a row vector is mean(A,2), giving a single mean value, whereas you might be expecting mean of each column of the row vector being returned instead, mean(A,1)
sle
on 5 Nov 2013
Edited: sle
on 5 Nov 2013
Hello Walter,
Thank you for your comments,
Would you please explain to me one more time what you meant by ordering by original index? Which matrix do you mean by that? I am confused since the component matrix I have is pc(100,100) and pc = pc'; V = V' and S = S'; where every matrix entry of V and S are 0s except at V(1,1) and S(1,1).
For the part of translating data to mean value, do you mean A or A'? Since my input matrix A(100,1) was translated to its mean(A,1) (1 single mean value) then transposed into B(1,100) before doing SVD (because input of PCA is the transpose of input of SVD). Output Aout has the same dimension as A which is 100-by-1
Please correct me if I am doing anything wrong. I very appreciate your help.
More Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!