Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 006d86e commit 4f61f59Copy full SHA for 4f61f59
sklearn/utils/tests/test_extmath.py
@@ -667,3 +667,18 @@ def test_weighted_median():
667
median = np.median(x)
668
wmedian = weighted_median(x, weights)
669
assert_almost_equal(median, wmedian)
670
+
671
672
+def test_weighted_median_equal_split():
673
+ rng = np.random.RandomState(0)
674
+ weights_left = rng.multinomial(20, [1/5.]*5, size=1)[0]
675
+ weights_right = rng.multinomial(20, [1/5.]*5, size=1)[0]
676
+ x = np.asarray(range(20))
677
+ rng.shuffle(x)
678
+ x = x[10:]
679
+ x.sort()
680
+ weights = np.hstack((weights_left, weights_right))
681
+ wmedian = weighted_median(x, weights)
682
+ sum_left = np.sum(weights[np.where(x < wmedian)])
683
+ sum_right = np.sum(weights[np.where(x > wmedian)])
684
+ assert_equal(sum_left, sum_right)
0 commit comments