Skip to content

Fix sporadic KBinsDiscretizer mismatches with scikit-learn - #8467

Open
viclafargue wants to merge 1 commit into
NVIDIA:mainfrom
viclafargue:fix-kbindiscretizer-mismatches
Open

Fix sporadic KBinsDiscretizer mismatches with scikit-learn#8467
viclafargue wants to merge 1 commit into
NVIDIA:mainfrom
viclafargue:fix-kbindiscretizer-mismatches

Conversation

@viclafargue

@viclafargue viclafargue commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Closes #3481 and #2933.

For the uniform strategy, the KBinsDiscretizer estimator could occasionally assign values to different bins than scikit-learn when they were close to a bin edge. Two differences caused this:

  • A small tolerance was added before assigning bins. This could move a value from immediately below an edge into the next bin.
  • A NumPy integer was passed to cupy.linspace. For float32 data, this could produce slightly different bin edges than passing a regular Python integer.

This PR removes the tolerance and uses the same searchsorted behavior as the most recent version of scikit-learn. It also passes a Python integer to cupy.linspace, making uniform bin-edge generation consistent.

For the quantile strategy, the test was originally marked as an expected failure because of bugs in older NumPy and CuPy percentile implementations. Those bugs have since been fixed.
Removing the quantile xfail works with scikit-learn 1.8 and earlier because its default linear interpolation matches cuML. Starting with scikit-learn 1.9, however, the default changed to averaged_inverted_cdf. A direct comparison would therefore test two different quantile methods. This PR explicitly configures scikit-learn to use linear interpolation, ensuring that the test compares equivalent behavior while remaining compatible with older supported versions.

@viclafargue
viclafargue requested a review from a team as a code owner August 11, 2026 09:15
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Aug 11, 2026
@viclafargue viclafargue added bug Something isn't working non-breaking Non-breaking change labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Cython / Python Cython or Python issue non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Sporadic failure in test_kbinsdiscretizer with uniform strategy

1 participant