Repository navigation
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
cakedev0
added a commit
to cakedev0/scikit-learn
that referenced
this pull request
Aug 31, 2026
Credits Saad Shabbir who independently proposed the same fix in scikit-learn#34451, which this PR supersedes. Co-authored-by: Saad Shabbir <[email protected]>
cakedev0
added a commit
to cakedev0/scikit-learn
that referenced
this pull request
Aug 31, 2026
Credits Saad Shabbir who independently proposed the same fix in scikit-learn#34451, which this PR supersedes. Co-authored-by: Saad Shabbir <[email protected]>
cakedev0
added a commit
to cakedev0/scikit-learn
that referenced
this pull request
Aug 31, 2026
Credits Saad Shabbir who independently proposed the same fix in scikit-learn#34451, which this PR supersedes. Co-authored-by: Saad Shabbir <[email protected]>
This branch has not been deployed
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.
Reference Issues/PRs
Fixes #34298
What does this implement/fix? Explain your changes.
QuantileTransformer._sparse_fitmaterialized a dense array of sizen_sampleswhen computing percentiles for a sparse column withignore_implicit_zeros=False, even when the column had very fewnon-zero entries. For very large, very sparse matrices this caused a
MemoryError(or unnecessary slowdown for moderately sparse cases).This PR adds
_sparse_column_percentile, which computes percentilesdirectly from the non-zero values plus a count of implicit zeros,
without allocating an
n_samples-length array. Since sparse input toQuantileTransformeris required to be non-negative, implicit zerosare guaranteed to occupy the lowest ranks when sorted, which makes an
analytical rank-based computation possible.
Changes:
_sparse_column_percentile()as a module-level helper._sparse_fit()to use it for the non-subsampled,ignore_implicit_zeros=Falsecode path (the one that previouslytriggered the bug).
Testing:
original dense-densifying approach on cases where the original
approach is still tractable (
np.allclosecomparison).QuantileTransformer/QuantileTransformtest suite insklearn/preprocessing/tests/test_data.pylocally — all passing.First time contributor introduction
This is my first contribution to scikit-learn. I'm Saad, an AI/ML
engineer based in Lahore, working mostly on RAG pipelines, agentic
systems, and backend ML infra day-to-day. I've been meaning to get
into open-source ML contributions for a while and picked this issue
because it was a self-contained, well-scoped numerical bug rather than
something touching the Cython internals — figured it was a reasonable
first PR to actually understand the codebase properly rather than
just skimming it. Looking forward to contributing more.
AI usage disclosure
I used AI assistance for:
Any other comments?
I reproduced the original bug locally before starting, and validated
the fix against the original (memory-hungry but correct) computation
to confirm numerical equivalence before touching the actual
_sparse_fitcode. Along the way I introduced a regression in thesubsampled branch (it stopped appending to
self.quantiles_), whichtest_quantile_transform_subsamplingcaught immediately — goodreminder of why that test exists. Happy to adjust the approach if
there's a preferred direction, or add more test coverage if reviewers
want it.