Пример #1
0
    def setPos(self, x, y):
        if self.showText:
            ty, ry = y, y + 18
        else:
            ty, ry = 0, y + 3
        pos = 0
        for r in self.rect:
            r.setPos(x + pos, ry)
            pos += r.rect().width()
        self.text.setPos(x, ty)

    def show(self):
        for r in self.rect:
            r.show()
        if self.showText:
            self.text.show()


if __name__ == "__main__":
    ap = QApplication(sys.argv)
    w = OWCN2RulesViewer()
    #data=orange.ExampleTable("../../doc/datasets/car.tab")
    data = orange.ExampleTable(r"E:\Development\Orange Datasets\UCI\car.tab")
    l = orngCN2.CN2UnorderedLearner()
    l.ruleFinder.ruleStoppingValidator = orange.RuleValidator_LRS()
    w.setRuleClassifier(l(data))
    w.setRuleClassifier(l(data))
    w.show()
    ap.exec_()
    def setLearner(self):
        if hasattr(self, "btnApply"):
            self.btnApply.setFocus()
        #progress bar
        self.progressBarInit()

        #learner / specific handling in case of EVC learning (completely different type of class)
        if self.useMaxRuleLength:
            maxRuleLength = self.MaxRuleLength
        else:
            maxRuleLength = -1

        if self.QualityButton == 2:
            self.learner = orngCN2.CN2EVCUnorderedLearner(
                width=self.BeamWidth,
                rule_sig=self.Alpha,
                att_sig=self.stepAlpha,
                min_coverage=self.MinCoverage,
                max_rule_complexity=maxRuleLength)
            if self.preprocessor:
                self.learner = self.preprocessor.wrapLearner(self.learner)
            self.learner.name = self.name
            #            self.learner.progressCallback=CN2ProgressBar(self)
            self.send("Learner", self.learner)
        else:
            self.learner = orngCN2.CN2UnorderedLearner()
            self.learner.name = self.name
            #            self.learner.progressCallback=CN2ProgressBar(self)
            #            self.send("Learner",self.learner)

            ruleFinder = orange.RuleBeamFinder()
            if self.QualityButton == 0:
                ruleFinder.evaluator = orange.RuleEvaluator_Laplace()
            elif self.QualityButton == 1:
                ruleFinder.evaluator = orngCN2.mEstimate(self.m)
            elif self.QualityButton == 3:
                ruleFinder.evaluator = orngCN2.WRACCEvaluator()

            ruleFinder.ruleStoppingValidator = orange.RuleValidator_LRS(
                alpha=self.stepAlpha,
                min_coverage=self.MinCoverage,
                max_rule_complexity=maxRuleLength)
            ruleFinder.validator = orange.RuleValidator_LRS(
                alpha=self.Alpha,
                min_coverage=self.MinCoverage,
                max_rule_complexity=maxRuleLength)
            ruleFinder.ruleFilter = orange.RuleBeamFilter_Width(
                width=self.BeamWidth)
            self.learner.ruleFinder = ruleFinder

            if self.CoveringButton == 0:
                self.learner.coverAndRemove = orange.RuleCovererAndRemover_Default(
                )
            elif self.CoveringButton == 1:
                self.learner.coverAndRemove = orngCN2.CovererAndRemover_multWeights(
                    mult=self.Weight)

            if self.preprocessor:
                self.learner = self.preprocessor.wrapLearner(self.learner)
            self.learner.name = self.name
            self.send("Learner", self.learner)

        self.classifier = None
        self.error()
        if self.data:
            oldDomain = orange.Domain(self.data.domain)
            learnData = orange.ExampleTable(oldDomain, self.data)
            self.learner.progressCallback = CN2ProgressBar(self)
            self.classifier = self.learner(learnData)
            self.learner.progressCallback = None
            self.classifier.name = self.name
            for r in self.classifier.rules:
                r.examples = orange.ExampleTable(oldDomain, r.examples)
            self.classifier.examples = orange.ExampleTable(
                oldDomain, self.classifier.examples)
            self.classifier.setattr("data", self.classifier.examples)
            self.error("")


##            except orange.KernelException, (errValue):
##                self.classifier=None
##                self.error(errValue)
##            except Exception:
##                self.classifier=None
##                if not self.data.domain.classVar:
##                    self.error("Classless domain.")
##                elif self.data.domain.classVar.varType == orange.VarTypes.Continuous:
##                    self.error("CN2 can learn only from discrete class.")
##                else:
##                    self.error("Unknown error")
        self.send("Classifier", self.classifier)
        self.send("Unordered CN2 Classifier", self.classifier)
        self.progressBarFinished()