Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix KBinsDiscretizer uniform strategy : wrong bin assignment caused by floating point errors when using uniform strategy #30962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Rishab260
Copy link
Contributor

@Rishab260 Rishab260 commented Mar 8, 2025

Reference Issues/PRs

Fixes: #30924

What does this implement/fix? Explain your changes.

Fix precision issues in KBinsDiscretizer when using the "uniform" strategy by replacing np.linspace (which relies on floating-point arithmetic) with decimal for exact bin edge computation.

Previously, floating-point rounding errors could accumulate, leading to slight inaccuracies in bin edge calculations.

Changes:-
  • Remove use of np.linspace and uses decimal for edge computation when using uniform strategy.
  • Added test test_kbinsdiscretizer_uniform_strategy
    • Correct bin edges
    • Uniform bin widths
    • Transformation and inverse transformation work correctly

Any other comments?

Any suggestions or feedback is highly appreciated. Thanks.

Copy link

github-actions bot commented Mar 8, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 4bd2f72. Link to the linter CI: here

@Rishab260
Copy link
Contributor Author

Hi @ogrisel, PTAL if this fix looks good to you? Thanks.

@Rishab260
Copy link
Contributor Author

Hi @thomasjpfan , could you please take a look at these changes? Thanks.

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

Successfully merging this pull request may close these issues.

KBinsDiscretizer uniform strategy bin assignment wrong due to floating point multiplication
1 participant