def test_classifies_instance_correctly(self):
     self.__update_stump()
     self.assertEqual(
         'no',
         self.outlook_stump.klass(
             instance.GoldInstance(['sunny', 'mild', 'normal', 'true'],
                                   'yes')))
     self.assertEqual(
         'yes',
         self.outlook_stump.klass(
             instance.GoldInstance(['overcast', 'mild', 'normal', 'true'],
                                   'yes')))
     self.assertEqual(
         'yes',
         self.outlook_stump.klass(
             instance.GoldInstance(['rainy', 'mild', 'normal', 'true'],
                                   'yes')))
     self.assertEqual(
         'no',
         self.outlook_stump.klass(
             instance.TestInstance(['sunny', 'mild', 'normal', 'true'])))
     self.assertEqual(
         'yes',
         self.outlook_stump.klass(
             instance.TestInstance(['overcast', 'mild', 'normal', 'true'])))
     self.assertEqual(
         'yes',
         self.outlook_stump.klass(
             instance.TestInstance(['rainy', 'mild', 'normal', 'true'])))
 def test_gold_intances_creation(self):
     instances = gold(datasetsDir(self) + 'numerical' + SEP + 'weather')
     self.assertEqual(4, len(instances), '4 instances should be present')
     self.assertEqual(
         ins.GoldInstance(['sunny', '21', 'normal', 'true'], 'yes'),
         instances[0])
     self.assertEqual(
         ins.GoldInstance(['rainy', '17.9', 'high', 'true'], 'no'),
         instances[3])
 def test_classes_can_be_set_on_gold_instance(self):
     gold = ins.GoldInstance(['bar','two'],'a')
     self.assertEqual(self.a, gold.klass_value)
     self.assertEqual(None, gold.classified_klass)
     gold.set_klass(self.b)
     self.assertEqual(self.a, gold.klass_value)
     self.assertEqual(self.b, gold.classified_klass)
 def test_gold_instance_creates_class(self):
     gold = ins.GoldInstance(['bar','two'],'a')
     self.assertEqual(2, len(gold.attrs))
     self.assertEqual('bar', gold.attrs[0])
     self.assertEqual('two', gold.attrs[1])
     self.assertEqual(self.a, gold.klass_value)
     self.assertEqual(None, gold.classified_klass)
    def test_get_attribute_value_from_instance_using_attribute(self):
        instance = ins.TrainingInstance(['bar','two'],'a')
        attr = attribute.Attribute('second', ['two','duo'], 1)
        self.assertEqual('two', instance.value(attr))
        
        test = ins.TestInstance(['bar','two'])
        self.assertEqual('two', test.value(attr))

        gold = ins.GoldInstance(['bar','two'],'a')
        self.assertEqual('two', gold.value(attr))
 def test_string_representation(self):
     instance = ins.TrainingInstance(['bar','two'],'a')
     self.assertEqual("[bar,two;a]", instance.__str__());
     
     instance = ins.TestInstance(['bar','two'])
     self.assertEqual("[bar,two; ]", instance.__str__());
     instance.set_klass('b')
     self.assertEqual("[bar,two;b]", instance.__str__());
             
     instance = ins.GoldInstance(['bar','two'],'a')
     self.assertEqual("[bar,two;a; ]", instance.__str__());
     instance.set_klass('b')
     self.assertEqual("[bar,two;a;b]", instance.__str__());
Exemple #7
0
 def gold(self, file_path):
     all_values = self.__get_all_values(file_path, self.GOLD)
     return inss.GoldInstances([ins.GoldInstance(values[:-1], values[-1]) for values in all_values if values is not None])