Skip to content

BUG: MLE for PCA mis-estimates rank #16730

Closed

Description

@larsoner

After #16224 it looks like this code no longer produces the correct result:

import numpy as np
from sklearn.decomposition import PCA
n_samples, n_dim = 1000, 10
X = np.random.RandomState(0).randn(n_samples, n_dim)
X[:, -1] = np.mean(X[:, :-1], axis=-1)  # true X dim is ndim - 1
pca_skl = PCA('mle', svd_solver='full')
pca_skl.fit(X)
assert pca_skl.n_components_ == n_dim - 1

Before #16224 this passed (n_components_ == 9) but after #16224 it gives 8. Not sure why this would happen given the singular value spectrum looks good:

import matplotlib.pyplot as plt
s = np.linalg.svdvals(X)
plt.stem(s)

Figure_1

Maybe an off-by-one error somewhere?

cc'ing @lschwetlick since it was your PR

Activity

  1. added this to the 0.23 milestone on Mar 21, 2020
  2. gorski-m commented on Mar 26, 2020

    @gorski-m
    Contributor

    Can I work on this?

  3. lschwetlick commented on Mar 26, 2020

    @lschwetlick
    Contributor

    So I'm not entirely sure but it's likely that it's related to what we're also discussing in this thread.
    @Reksbril from my side I'm a bit stuck, so if you have any ideas go for it :)

  4. NicolasHug commented on Apr 1, 2020

    @NicolasHug
    Member

    Thanks for the report @larsoner

    @adrinjalali @jnothman should we temporarily revert the changes introduced in #16224?

    Slightly related, the fact that we allow n_components=0 (which returns an empty array) sounds like a bug to me

  5. adrinjalali commented on Apr 1, 2020

    @adrinjalali
    Member

    I don't think reverting that PR would be a good idea, since it's fixing an issue itself (we could exclude it from the release though).

    cc'ing @agramfort

  6. NicolasHug commented on Apr 1, 2020

    @NicolasHug
    Member

    It definitely seems to have introduced a worse bug that what was fixed. What @larsoner reported will probably affect many more users. If no fix can be found in a reasonable time, I think we should revert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions