8000 [MRG+1] fowlkes_mallows_score: more unit tests (Fixes #8101) (#8140) · scikit-learn/scikit-learn@2cb7e47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cb7e47

Browse files
devanshdalaljnothman
authored andcommitted
[MRG+1] fowlkes_mallows_score: more unit tests (Fixes #8101) (#8140)
1 parent 543b056 commit 2cb7e47

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sklearn/metrics/cluster/tests/test_supervised.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,26 @@ def test_fowlkes_mallows_score():
239239
worst_score = fowlkes_mallows_score([0, 0, 0, 0, 0, 0],
240240
[0, 1, 2, 3, 4, 5])
241241
assert_almost_equal(worst_score, 0.)
242+
243+
244+
def test_fowlkes_mallows_score_properties():
245+
# handcrafted example
246+
labels_a = np.array([0, 0, 0, 1, 1, 2])
247+
labels_b = np.array([1, 1, 2, 2, 0, 0])
248+
expected = 1. / np.sqrt((1. + 3.) * (1. + 2.))
249+
# FMI = TP / sqrt((TP + FP) * (TP + FN))
250+
251+
score_original = fowlkes_mallows_score(labels_a, labels_b)
252+
assert_almost_equal(score_original, expected)
253+
254+
# symetric property
255+
score_symetric = fowlkes_mallows_score(labels_b, labels_a)
256+
assert_almost_equal(score_symetric, expected)
257+
258+
# permutation property
259+
score_permuted = fowlkes_mallows_score((labels_a + 1) % 3, labels_b)
260+
assert_almost_equal(score_permuted, expected)
261+
262+
# symetric and permutation(both together)
263+
score_both = fowlkes_mallows_score(labels_b, (labels_a + 2) % 3)
264+
assert_almost_equal(score_both, expected)

0 commit comments

Comments
 (0)
0