5
$\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$
6
  • 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
    Mar 16, 2018 at 16:27
  • $\begingroup$ Are you doing PCA with or without centering? $\endgroup$
    – whuber
    Mar 16, 2018 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
    Mar 16, 2018 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$ Mar 16, 2018 at 17:37
  • 1
    $\begingroup$ If you use scikit's PCA then it does centering for you. $\endgroup$
    – amoeba
    Mar 16, 2018 at 22:12

1 Answer 1

2
$\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$
2
  • $\begingroup$ Could you please explain why this is so? $\endgroup$
    – Sos
    Feb 29, 2020 at 10:01
  • $\begingroup$ Because the rank of PC's matrix should be less than or equal to n. Recall the linear independence. $\endgroup$
    – kurtkim
    Jun 23, 2020 at 17:54

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.