Ejemplo n.º 1
0
    def generate_negative_rules(self, train, confident_value_pass):
        confident_value = 0
        class_value_arr = self.get_class_value_array(train)
        for i in range(0, len(self.ruleBase)):
            rule_negative = Rule()
            rule_negative.antecedent = self.ruleBase[i].antecedent
            positive_rule_class_value = self.ruleBase[i].get_class()
            print("the positive rule class value is " +
                  str(positive_rule_class_value) + " ,the i is :" + str(i))
            rule_negative.setClass(positive_rule_class_value)

            for j in range(0, len(class_value_arr)):
                class_type = int(class_value_arr[j])
                if positive_rule_class_value != class_type:  # need to get another class value for negative rule

                    rule_negative.setClass(
                        class_type)  # change the class type in the rule
                    confident_value = rule_negative.calculate_confident(
                        self.data_row_array)
                    print("The calculation confident value is :" +
                          str(confident_value))

                    if confident_value >= confident_value_pass:
                        rule_negative.weight = confident_value
                        if not (self.duplicated_negative_rule(rule_negative)):

                            for k in range(0, len(rule_negative.antecedent)):
                                print("antecedent L_ " +
                                      str(rule_negative.antecedent[j].label))
                            print("class value " +
                                  str(rule_negative.get_class()))
                            print(" weight  " + str(rule_negative.weight))

                            print("positive_rule_class_value" +
                                  str(positive_rule_class_value))
                            print("class_type" + str(class_type))
                            self.negative_rule_base_array.append(rule_negative)