Exemplo n.º 1
0
 def test_recallFunctionAlone(self):
     #Tests the tuple generation from the sentences
     labeled = hw5.generate_tuples_from_file(self.training_file)
     labeled[0][3] = ("phosphatases", "O") # incorrect boundary (ends early)
     labeled[0][5] = ("5", "O") # incorrect boundary (begins late)
     labeled[0][6] = ("-", "B") # incorrect boundary (begins late)
     labeled[1][4] = ("the", "B") # should be O
     train_tups = [tup for sent in self.train_tups for tup in sent]
     labeled = [tup for sent in labeled for tup in sent]
     recall = hw5.recall(train_tups, labeled)
     # 1 correct / 3 possible
     self.assertAlmostEqual(.33333333, recall)
     labeled = hw5.generate_tuples_from_file(self.training_file)
     labeled[1][4] = ("the", "B") # should be O
     labeled = [tup for sent in labeled for tup in sent]
     recall = hw5.recall(train_tups, labeled)
     # 3 correct / 3 possible
     self.assertEqual(1, recall)
Exemplo n.º 2
0
 def test_f1Function(self):
     #Tests the tuple generation from the sentences
     labeled = hw5.generate_tuples_from_file(self.training_file)
     labeled[0][3] = ("phosphatases", "O") # incorrect boundary (ends early)
     labeled[0][5] = ("5", "O") # incorrect boundary (begins late)
     labeled[0][6] = ("-", "B") # incorrect boundary (begins late)
     labeled[1][4] = ("the", "B") # should be O
     train_tups = [tup for sent in self.train_tups for tup in sent]
     labeled = [tup for sent in labeled for tup in sent]
     f1 = hw5.f1(train_tups, labeled)
     realf1 = (2 * .25 * .333333) / (.25 + .333333)
     self.assertAlmostEqual(realf1, f1, places=5)
     labeled = hw5.generate_tuples_from_file(self.training_file)
     labeled[1][4] = ("the", "B") # should be O
     labeled = [tup for sent in labeled for tup in sent]
     f1 = hw5.f1(train_tups, labeled)
     realf1 = (2 * .75 * 1) / (.75 + 1)
     self.assertAlmostEqual(realf1, f1, places=5)
Exemplo n.º 3
0
 def test_precisionFunctionAlone(self):
     #Tests the tuple generation from the sentences
     labeled = hw5.generate_tuples_from_file(self.training_file)
     labeled[0][3] = ("phosphatases", "O") # incorrect boundary (ends early)
     labeled[0][5] = ("5", "O") # incorrect boundary (begins late)
     labeled[0][6] = ("-", "B") # incorrect boundary (begins late)
     labeled[1][4] = ("the", "B") # should be O
     train_tups = [tup for sent in self.train_tups for tup in sent]
     labeled = [tup for sent in labeled for tup in sent]
     precision = hw5.precision(train_tups, labeled)
     # 1 correct / 4 guessed
     self.assertEqual(.25, precision)
     labeled = hw5.generate_tuples_from_file(self.training_file)
     labeled[1][4] = ("the", "B") # should be O
     labeled = [tup for sent in labeled for tup in sent]
     precision = hw5.precision(train_tups, labeled)
     # 3 correct / 4 guessed
     self.assertEqual(.75, precision)
 def setUp(self):
     #Sets the Training File Path
     # Feel free to edit to reflect where they are on your machine
     self.training_file = "minitrain.txt"
     self.train_tups = hw5.generate_tuples_from_file(self.training_file)