Beispiel #1
0
    def __init__(self, preprocessors, base_rules, params):
        super().__init__(preprocessors, base_rules)
        self.progress_advance_callback = None
        assert params is not None
        self.params = params

        # top-level control procedure (rule ordering)
        self.rule_ordering = params["Rule ordering"]

        # top-level control procedure (covering algorithm)
        self.covering_algorithm = params["Covering algorithm"]
        if self.covering_algorithm == "exclusive":
            self.cover_and_remove = self.exclusive_cover_and_remove
        elif self.covering_algorithm == "weighted":
            self.gamma = params["Gamma"]
            self.cover_and_remove = self.weighted_cover_and_remove

        # bottom-level search procedure (search algorithm)
        self.rule_finder.search_algorithm.beam_width = params["Beam width"]

        # bottom-level search procedure (search strategy)
        self.rule_finder.search_strategy.constrain_continuous = True

        # bottom-level search procedure (search heuristics)
        evaluation_measure = params["Evaluation measure"]
        if evaluation_measure == "entropy":
            evaluator = EntropyEvaluator()
        elif evaluation_measure == "laplace":
            evaluator = LaplaceAccuracyEvaluator()
        elif evaluation_measure == "wracc":
            evaluator = WeightedRelativeAccuracyEvaluator()
        self.rule_finder.quality_evaluator = evaluator

        # bottom-level search procedure (over-fitting avoidance heuristics)
        min_rule_cov = params["Minimum rule coverage"]
        max_rule_length = params["Maximum rule length"]
        self.rule_finder.general_validator.min_covered_examples = min_rule_cov
        self.rule_finder.general_validator.max_rule_length = max_rule_length

        # bottom-level search procedure (over-fitting avoidance heuristics)
        default_alpha = params["Default alpha"]
        parent_alpha = params["Parent alpha"]
        self.rule_finder.significance_validator.default_alpha = default_alpha
        self.rule_finder.significance_validator.parent_alpha = parent_alpha
Beispiel #2
0
# ADD COMMAND TO DEFINE LEARNER HERE
learners = {}

for beam_width in range(3, 11):
    for min_covered_examples in range(7, 21):
        for max_rule_length in range(2, 6):
            if category == 'unordered':
                learner = CN2UnorderedLearner()
            else:
                learner = CN2Learner()

            if evaluator == 'laplace':
                learner.rule_finder.quality_evaluator = LaplaceAccuracyEvaluator(
                )
            else:
                learner.rule_finder.quality_evaluator = EntropyEvaluator()
            learner.rule_finder.search_algorithm.beam_width = beam_width
            learner.rule_finder.general_validator.min_covered_examples = min_covered_examples
            learner.rule_finder.general_validator.max_rule_length = max_rule_length
            learners[category + '_' + evaluator + '_' + str(beam_width) + '_' +
                     str(min_covered_examples) + '_' +
                     str(max_rule_length)] = learner

# We want to test our model now. The CrossValidation() function will do all the
# work in this case, which includes splitting the whole dataset into train and test subsets,
# then train the model, and produce results.
# So, simply initialize the CrossValidation() object from the 'testing' library
# and call it with input arguments 1) the dataset and 2) the learner.
# Note that the 'learner' argument should be in array form, i.e. '[learner]'.
cv = CrossValidation(k=10, random_state=44)
results = {}