Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MNT Refactor_average_weighted_percentile to avoid double sort#31775

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
lucyleeow wants to merge5 commits intoscikit-learn:main
base:main
Choose a base branch
Loading
fromlucyleeow:refactor_weighted_percentile

Conversation

lucyleeow
Copy link
Member

Reference Issues/PRs

Supercedes#30945

What does this implement/fix? Explain your changes.

Refactor_average_weighted_percentile so we are not just performing_weighted_percentile twice, thus avoids sorting and computing cumulative sum twice.

#30945 essentially uses the sorted indicies and calculates_weighted_percentile(-array, 100-percentile_rank) - this was verbose and required computing cumulative sum again on the negative (you could have used symmetry to avoid computing cumulative sum in cases when fraction above is greater than 0 - i.e.,g>0 from Hyndman and Fan)

I've followed the Hyndman and Fan computation more closely and calculateg and just usej+1 (since we already knowj). This did make handling the case wherej+1 had a sample weight of 0 (or when you have sample weight of 0 at the end of the array) more complex.

Any other comments?

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedJul 17, 2025
edited
Loading

✔️ Linting Passed

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

Generated for commit:ba57727. Link to the linter CI:here


result = xp.where(
is_fraction_above,
array[percentile_in_sorted, col_indices],
Copy link
MemberAuthor

@lucyleeowlucyleeowJul 17, 2025
edited
Loading

Choose a reason for hiding this comment

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

I initially thought this should bepercentile_plus_one_in_sorted as from the paper, when g>0,$\gamma=1$,butsearchsorted defaults to left (equals is on the right), whereas the paper definedj <= pn < j+1 butsearchsorted effectively givesi-1 < pn <= i whereas the paper hadj <= pn < j+1. This means that whenpn is greater than the LHS,searchsorted'si equalsj+1, from the paper.

When the quantile exactly matches an index,searchsorted'si equalsj, from the paper (as the equals is on opposite sides in paper vssearchsorted).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@lucyleeow

[8]ページ先頭

©2009-2025 Movatter.jp