@@ -239,3 +239,26 @@ def test_fowlkes_mallows_score():
239
239
worst_score = fowlkes_mallows_score ([0 , 0 , 0 , 0 , 0 , 0 ],
240
240
[0 , 1 , 2 , 3 , 4 , 5 ])
241
241
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