Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f61f59

Browse files
committed
Add more tests
1 parent 006d86e commit 4f61f59

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sklearn/utils/tests/test_extmath.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,18 @@ def test_weighted_median():
667667
median = np.median(x)
668668
wmedian = weighted_median(x, weights)
669669
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

Comments
 (0)