3
$\begingroup$

Recently I've been interested in applying PCA to a dataset I have and I wanted to develop a deep understanding of what I would actually be doing when I implement it.

Today I encountered two confronting answers to the question of what is the maximum number of principal components. The two answers are these ones:

Do any of you know what is the meaning of that extra component that sklearn's PCA is offering?

$\endgroup$
  • 1
    $\begingroup$ If the number of samples $n$ is less than or equal to the number of features, the $n$-th PC will be constant zero (eigenvalue = 0). This is what sklearn will presumably return. The number of non-trivial PCs is $n-1$ as per the linked answer. $\endgroup$ – amoeba says Reinstate Monica Mar 16 '18 at 16:27
  • $\begingroup$ Are you doing PCA with or without centering? $\endgroup$ – whuber Mar 16 '18 at 16:31
  • 1
    $\begingroup$ @whuber I don't think sklearn.decomposition.PCA can do PCA without centering. I don't see such an option in the documentation. $\endgroup$ – amoeba says Reinstate Monica Mar 16 '18 at 16:41
  • 1
    $\begingroup$ @amoeba Completely on point! I just checked what is the n-th principal component of my data and it is always 0! Problem solved :) $\endgroup$ – Marcos Galletero Romero Mar 16 '18 at 17:37
  • 1
    $\begingroup$ If you use scikit's PCA then it does centering for you. $\endgroup$ – amoeba says Reinstate Monica Mar 16 '18 at 22:12
1
$\begingroup$

Per @amoeba's comments:

If the number of samples $n$ is less than or equal to the number of features, the $n$-th PC will be constant zero (eigenvalue = 0). This is what sklearn will presumably return. The number of non-trivial PCs is $n−1$ as per the linked answer.

$\endgroup$
  • $\begingroup$ Could you please explain why this is so? $\endgroup$ – Sos Feb 29 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.