Remove unnecessary restriction on number of samples in IncrementalPCA #30224
Merged
adrinjalali merged 8 commits intoNov 7, 2024
Merged
Conversation
ogrisel
approved these changes
Nov 5, 2024
ogrisel
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR. Some minor feedback below, but otherwise LGTM.
We probably need better tests (e.g. on non-spherical data) for this estimator, and we could also clarify what are the expectations in terms of accuracy between the full-batch and incremental version of PCA, but this is beyond the scope of this PR.
Contributor
Author
|
Thanks for the feedback! I have implemented all of your suggestions |
d2d4f27 to
c752837
Compare
adrinjalali
approved these changes
Nov 7, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently when calling
IncrementalPCA.partial_fit()the number of samples inXalways has to be greater or equal to the number of PCA components due to this hardcoded checkscikit-learn/sklearn/decomposition/_incremental_pca.py
Line 303 in 6e90391
However, this restriction actually only needs to apply to the first call to$U$ and $\Sigma$ , none of the algorithms steps (see original paper https://www.cs.toronto.edu/~dross/ivt/RossLimLinYang_ijcv.pdf) require any size restrictions on the number of samples in the subsequent batches passed to
partial_fit(), which performs the initial SVD decomposition. Once this first call has established the initialpartial_fit. The current error message hence unnecessary restricts the usage of IncrementalPCA, in particular in online applications where data might arrive in batches of different sizes.This PR, updates the aforementioned check to only apply to the first call of
partial_fitand adds a non-regression test for this issue.