Пример #1
0
 def test_bed_confusion_matrix_datasets(self):
     '''
     Test BED-based confusion matrix upon a dataset.
     '''
     hypothesis = HYPOTHESIS_STARGAZER
     reference = HEARST_1997_STARGAZER
     value = boundary_confusion_matrix(hypothesis, reference)
     hyp_p = precision(value)
     hyp_r = recall(value)
     hyp_f = fmeasure(value)
     # Precision
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,2']), 0.33333333)
     # Recall
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,2']), 0.33333333)
     # FMeasure
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,1']), 0.72727272)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,1']), 0.58333333)
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,2']), 0.6)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,2']), 0.5)
Пример #2
0
 def test_bed_confusion_matrix_datasets(self):
     '''
     Test BED-based confusion matrix upon a dataset.
     '''
     hypothesis = HYPOTHESIS_STARGAZER
     reference = HEARST_1997_STARGAZER
     value = boundary_confusion_matrix(hypothesis, reference)
     hyp_p = precision(value)
     hyp_r = recall(value)
     hyp_f = fmeasure(value)
     # Precision
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_p['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_p['stargazer,h2,2']), 0.33333333)
     # Recall
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,1']), 0.57142857)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,1']), 0.41176470)
     self.assertAlmostEquals(float(hyp_r['stargazer,h1,2']), 0.42857142)
     self.assertAlmostEquals(float(hyp_r['stargazer,h2,2']), 0.33333333)
     # FMeasure
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,1']), 0.72727272)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,1']), 0.58333333)
     self.assertAlmostEquals(float(hyp_f['stargazer,h1,2']), 0.6)
     self.assertAlmostEquals(float(hyp_f['stargazer,h2,2']), 0.5)
Пример #3
0
 def test_boundary_confusion_matrix(self):
     '''
     Test confusion matrix.
     '''
     cm = boundary_confusion_matrix([
         set([]),
         set([2]),
         set([]),
         set([]),
         set([1]),
         set([1]),
         set([1]),
         set([1])
     ], [
         set([1]),
         set([1]),
         set([]),
         set([1]),
         set([]),
         set([1]),
         set([]),
         set([])
     ],
                                    boundary_format=BoundaryFormat.sets)
     self.assertEqual(cm[None][1], 2)
     self.assertEqual(cm[1][None], 1)
     self.assertEqual(cm[None][2], 0)
     self.assertEqual(cm[2][None], 0)
     self.assertEqual(cm[2][1], 1)
     self.assertEqual(cm[1][2], 0)
     self.assertEqual(cm[1][1], Decimal('1.5'))
     self.assertEqual(cm[2][2], 0)
Пример #4
0
 def test_bed_confusion_matrix(self):
     '''
     Test BED-based confusion matrix upon two segmentations.
     '''
     hypothesis = (5,5,5,5,1)
     reference = HEARST_1997_STARGAZER['stargazer']['2']
     value = boundary_confusion_matrix(hypothesis, reference)
     self.assertAlmostEquals(float(precision(value)), 0.23076923)
     self.assertAlmostEquals(float(recall(value)), 0.23076923)
     self.assertAlmostEquals(float(fmeasure(value)), 0.375)
Пример #5
0
 def test_bed_confusion_matrix(self):
     '''
     Test BED-based confusion matrix upon two segmentations.
     '''
     hypothesis = (5, 5, 5, 5, 1)
     reference = HEARST_1997_STARGAZER['stargazer']['2']
     value = boundary_confusion_matrix(hypothesis, reference)
     self.assertAlmostEquals(float(precision(value)), 0.23076923)
     self.assertAlmostEquals(float(recall(value)), 0.23076923)
     self.assertAlmostEquals(float(fmeasure(value)), 0.375)
Пример #6
0
def example_in_paper_test():
    gold = [2, 3, 6]
    h_list = [[5, 6], [2, 2, 7], [2, 3, 3, 3], [1, 1, 3, 1, 5]]
    for n, h in enumerate(h_list):
        cm = boundary_confusion_matrix(h, gold)
        print("第%d次实验" % int(n + 1))
        # The P, R and F values are different from those in the normal method because it will correct the near missing.
        print("P=%.4f, R=%.4f, F=%.4f" %
              (precision(cm), recall(cm), fmeasure(cm)))
        print("1-Pk=%.3f, 1-WD=%.3f, B=%.3f, S=%.3f" %
              (pk(h, gold,
                  one_minus=True), WD(h, gold, one_minus=True,
                                      window_size=2), B(h, gold), S(h, gold)))
Пример #7
0
 def test_boundary_confusion_matrix(self):
     '''
     Test confusion matrix.
     '''
     cm = boundary_confusion_matrix(
         [set([]), set([2]), set([]), set([]), set([1]), set([1]),
          set([1]), set([1])],
         [set([1]), set([1]), set([]), set([1]), set([]), set([1]),
          set([]), set([])],
         boundary_format=BoundaryFormat.sets)
     self.assertEqual(cm[None][1], 2)
     self.assertEqual(cm[1][None], 1)
     self.assertEqual(cm[None][2], 0)
     self.assertEqual(cm[2][None], 0)
     self.assertEqual(cm[2][1], 1)
     self.assertEqual(cm[1][2], 0)
     self.assertEqual(cm[1][1], Decimal('1.5'))
     self.assertEqual(cm[2][2], 0)