Repository navigation
FIX: Fix QuantileTransformer(ignore_implicit_zeros=True) sub-sampling behavior - #32587
Conversation
QuantileTransformer(ignore_implicit_zeros=True) sub-sampling behaviorQuantileTransformer(ignore_implicit_zeros=True) sub-sampling behavior
|
I'd add a change log entry, even if no one has reported a bug people might notice a change in behaviour. The entry is the way we want people to answer that kind of question for themselves without posting here. Fix looks good to me. Not thought about the test yet. |
…bug (scikit-learn#32587) Add deterministic regression test that constructs a very sparse CSC matrix with two nearly-identical columns (one with subsample - 1 nonzeros, the other with subsample + 1 nonzeros) and verifies that the transformed columns are not degenerate after fit/transform. For large declared n_samples, the bug could create a zero-sized column sample leading to collapsed quantiles (all zeros) for some columns. References: scikit-learn#32587
…eros=True When ignore_implicit_zeros=True, use subsample directly instead of scaling by n_samples to avoid zero-sized column samples. Also add max(1) guard for the else case. Fixes scikit-learn#32587
|
Ping @snath-xoc, I was told you're working on |
snath-xoc
left a comment
There was a problem hiding this comment.
Thank you for this @cakedev0 , overall looks solid, I suggested one change in the tests to make sure we do not have fallback to the degenerate case that this PR should be fixing. Overall looks good otherwise and good spot!
P.S. which did you manage to open the issue [TODO] yet? |
Co-authored-by: Shruti Nath <[email protected]>
…dev0/scikit-learn into fix/quantile_tr_sparse_ignore_zeros
|
I had not created the TODO issue yet, I just did it: #34298 |
snath-xoc
left a comment
There was a problem hiding this comment.
Thank you @cakedev0 for this, I suggested some more documentation under _sparse_fit so that subsampling behaviour changes is noted. Not sure if that is the right place, feel free to move it around.
Otherwise LGTM I suppose we would need some follow-up PRs to look more closely at #34298 for the ignore_implicit_zeros=False and len(column_nnz_data) <= subsample case?
glemaitre
left a comment
There was a problem hiding this comment.
It looks good. Just a couple of nitpicks.
|
@glemaitre I think we can merge this? |
…ng behavior (scikit-learn#32587) Co-authored-by: Shruti Nath <[email protected]>
…ng behavior (scikit-learn#32587) Co-authored-by: Shruti Nath <[email protected]>
…ng behavior (scikit-learn#32587) Co-authored-by: Shruti Nath <[email protected]>
…ng behavior (scikit-learn#32587) Co-authored-by: Shruti Nath <[email protected]>
…ng behavior (scikit-learn#32587) Co-authored-by: Shruti Nath <[email protected]>
Reference Issues/PRs
Fixes: #32585
What does this implement/fix? Explain your changes.
Fix the logic for the sub-sampling (only affect the case
ignore_implicit_zeros=True)Adds a non-regression test.
Any other comments?
While reviewing the PR, you might notice "behavior discontinuity" that this PR fixes also exists for the case
ignore_implicit_zeros=False. But for this case, it doesn't incur unexpected/incorrect results, just unexpectedly long/short runtime. See issue #34298 about that.I haven't written a change-log as nobody reported the bug except me, and I found it just by reading the code... Let me know if this is needed.