Ejemplo n.º 1
0
    def generate_negative_rules(self, train, confident_value_pass, zone_confident_pass):

        class_value_arr = self.get_class_value_array(train)
        self.prepare_data_rows(train)
        for i in range(0, len(self.rule_base_array)):
            rule_negative = Rule(self.data_base)
            rule_negative.antecedent = self.rule_base_array[i].antecedent
            positive_rule_class_value = self.rule_base_array[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
                    rule_negative.calculate_confident_support(self.data_row_array)
                    print("Negative rule's  confident value is :" + str(rule_negative.confident_value))

                    if rule_negative.confident_value > confident_value_pass and rule_negative.zone_confident > zone_confident_pass:
                        rule_negative.weight = rule_negative.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]))
                            # print("Negative rule's class value " + str(rule_negative.get_class()))
                            # print(" Negative rule's weight, confident_vale  " + str(rule_negative.weight))
                            # print(" Negative rule's zone confident value   " + str(rule_negative.zone_confident))
                            # print("Negative rule's positive_rule_class_value" + str(positive_rule_class_value))
                            # print("Negative rule's class_type" + str(class_type))
                            self.negative_rule_base_array.append(rule_negative)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def generate_negative_rules_by_rule_cover_number(self, train, confident_value_pass, zone_confident_pass):

        class_value_arr = self.get_class_value_array(train)
        self.prepare_data_rows(train)
        for i in range(0, len(self.rule_base_array)):
            rule_negative = Rule(self.data_base)
            rule_negative.antecedent = self.rule_base_array[i].antecedent
            positive_rule_class_value = self.rule_base_array[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)
            best_rule_cover_accurate = self.rule_base_array[i].rule_cover_accurate
            has_negative_rule = False
            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.calculate_confident_support(self.data_row_array)
                    print("Negative rule's  confident value is :" + str(rule_negative.confident_value))

                    if rule_negative.rule_cover_accurate > best_rule_cover_accurate:
                        best_negative_rule = rule_negative.clone()
                        best_negative_rule.setClass(class_type)  # change the class type in the rule
                        best_negative_rule.negative_rule = True
                        has_negative_rule = True

            if (not (self.duplicated_negative_rule(rule_negative))) and has_negative_rule:

                for k in range(0, len(rule_negative.antecedent)):
                    print("antecedent L_ " + str(rule_negative.antecedent[j]))
                # print("Negative rule's class value " + str(rule_negative.get_class()))
                # print(" Negative rule's weight, confident_vale  " + str(rule_negative.weight))
                # print(" Negative rule's zone confident value   " + str(rule_negative.zone_confident))
                # print("Negative rule's positive_rule_class_value" + str(positive_rule_class_value))
                # print("Negative rule's class_type" + str(class_type))
                self.rule_base_array.pop(i)
                self.rule_base_array.append(best_negative_rule)