Skip to content

Fix _weighted_percentile for percentile=0 - #20528

Merged
rth merged 3 commits into
scikit-learn:mainfrom
mlondschien:bugfix-weighted-percentile
Jul 19, 2021
Merged

rth merged 3 commits into
scikit-learn:mainfrom
mlondschien:bugfix-weighted-percentile

Conversation

@mlondschien

Copy link
Copy Markdown
Contributor

Related: #20526

On master:

In [3]: _weighted_percentile(
    ...:     np.array(range(6)),
    ...:     np.array([0, 0, 1, 1, 1, 0]),
    ...:     0
    ...:  )
Out[3]: 0

In [4]: _weighted_percentile(
    ...:     np.array(range(6)),
    ...:     np.array([0, 0, 1, 1, 1, 0]),
    ...:     100
    ...:  )
Out[4]: 4

The issue here is that

In [5]: np.searchsorted([0, 0, 1, 2, 3, 4, 4], 0)
Out[5]: 0

In [6]: np.searchsorted([0, 0, 1, 2, 3, 4, 4], 4)
Out[6]: 5

This fixes this behaviour.

@TomDLT TomDLT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Could you add a bugfix entry in doc/whats_new/v1.0.rst, with ideally a list of the affected estimators ?

@rth rth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mlondschien !

@rth
rth merged commit f081f58 into scikit-learn:main Jul 19, 2021
@mlondschien
mlondschien deleted the bugfix-weighted-percentile branch July 20, 2021 07:29
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
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.

3 participants