Skip to content
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

Allow for event weights when calculating percentile cuts #224

Open
gschwefer opened this issue Apr 19, 2023 · 3 comments
Open

Allow for event weights when calculating percentile cuts #224

gschwefer opened this issue Apr 19, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@gschwefer
Copy link

When calculating a cut using cuts.calculate_percentile_cut, it would be useful to have to the option to associate weight with the values argument.

This can be done through an extra argument weights to cuts.calculate_percentile_cut that defaults to equal weights for all values. Then the np.nanpercentile in cuts.calculate_percentile_cut would have to be replaced by a function that calculates weighted percentiles.

@gschwefer
Copy link
Author

If this strategy seems ok I can quickly open a pull request

@gschwefer gschwefer self-assigned this Apr 19, 2023
@gschwefer gschwefer added the enhancement New feature or request label Apr 19, 2023
@maxnoe
Copy link
Member

maxnoe commented Apr 19, 2023

Yes, sounds good, thanks!

I didn't consider weights inside bins important as of now, since we I'd expect the binning to be fine enough so that it doesn't matter, however if you have a usecase that requires taking the weights into account in bins, fine to add this here.

However, we'd of course need functions supporting weights for quantiles, which I didn't find in numpy or scipy with a quick search. So we might need to implement this ourselves using cumsum and searchsorted as proposed here:

https://stackoverflow.com/a/75321415/3838691

@gschwefer
Copy link
Author

Yes, the weighted quantile stuff I have implemented in a custom function similar to the one in stackoverflow. I'll open a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants