-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
weighted_percentile should error/warn when all sample weights 0 #31032
Copy link
Copy link
Closed
Labels
Description
Describe the bug
Noticed while working on #29431
Steps/Code to Reproduce
See the following test:
scikit-learn/sklearn/utils/tests/test_stats.py
Lines 67 to 73 in cd0478f
| def test_weighted_percentile_zero_weight(): | |
| y = np.empty(102, dtype=np.float64) | |
| y.fill(1.0) | |
| sw = np.ones(102, dtype=np.float64) | |
| sw.fill(0.0) | |
| value = _weighted_percentile(y, sw, 50) | |
| assert approx(value) == 1.0 |
Expected Results
Error or warning should probably be given. You're effectively asking for a quantile of a empty array.
Actual Results
When all sample weights are 0, what happens is that percentile_in_sorted (as in the index of desired observation in array is the) is 101 (the last item). We should probably add a check and give a warning when sample_weights is all zero
Versions
n/aReactions are currently unavailable