Exemplo n.º 1
0
 def test_throws_error_if_conitinuous_atributes_are_present(self):
     try:
         path = datasetsDir(self) + 'numerical' + SEP + 'weather'
         a,c = metadata(path)
         dt = decisiontree.DecisionTree(training(path), a, c)
         dt.train()
         self.fail('should have thrown an error')
     except inv.InvalidDataError:
         pass
Exemplo n.º 2
0
 def test_maximum_gain_raito_stump_is_selected(self):
     path = datasetsDir(self) + 'test_phones' + SEP + 'phoney'
     _training = training(path)
     a, c = metadata(path)
     tree = decisiontree.DecisionTree(_training, a, c)
     decision_stumps = tree.possible_decision_stumps([], _training)
     
     max_gr_stump = tree.maximum_gain_ratio(decision_stumps)
     self.assertEqual('pda', max_gr_stump.attribute.name)
Exemplo n.º 3
0
 def test_filter_does_not_affect_the_original_training(self):
     path = datasetsDir(self) + 'minigolf' + SEP + 'weather'
     a, c = metadata(path)
     tree = decisiontree.DecisionTree(training(path), a, c)
     tree.train()
     outlook = tree.attributes[0]
     self.assertEqual(9, len(tree.training))
     filtered = tree.training.filter(outlook, 'sunny')
     self.assertEqual(9, len(tree.training))
     self.assertEqual(4, len(filtered))
Exemplo n.º 4
0
 def test_tree_creation(self):
     path = datasetsDir(self) + 'test_phones' + SEP + 'phoney'
     a, c = metadata(path)
     tree = decisiontree.DecisionTree(training(path), a, c)
     tree.train()
     self.assertNotEqual(None, tree)
     self.assertNotEqual(None, tree.root)
     self.assertEqual('band', tree.root.attribute.name)
     self.assertEqual(1, len(tree.root.children))
     self.assertEqual('size', tree.root.children['tri'].attribute.name)
Exemplo n.º 5
0
 def test_ignores_selected_attributes_in_next_recursive_iteration(self):
     path = datasetsDir(self) + 'minigolf' + SEP + 'weather'
     a, c = metadata(path)
     tree = decisiontree.DecisionTree(training(path), a, c)
     tree.train()
     self.assertEqual('outlook', tree.root.attribute.name)
     children = tree.root.children
     self.assertEqual(2, len(children))
     
     sunny = children['sunny']
     self.assertEqual('temperature', sunny.attribute.name)
     self.assertEqual(0, len(sunny.children))
     
     rainy = children['rainy']
     self.assertEqual('windy', rainy.attribute.name)
     self.assertEqual(0, len(rainy.children))