Exemple #1
0
    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()
Exemple #2
0
import orngCN2

data = orange.ExampleTable("titanic.tab")

# create learner
learner = orngCN2.CN2Learner()

cl = learner(data)
for r in cl.rules:
    print orngCN2.ruleToString(r)
print "*****"

learner = orngCN2.CN2UnorderedLearner()

learner.ruleFinder = orange.RuleBeamFinder()
learner.ruleFinder.evaluator = orngCN2.mEstimate(m=50)

cl = learner(data)
for r in cl.rules:
    print orngCN2.ruleToString(r)
print "****"

learner = orngCN2.CN2SDUnorderedLearner()

learner.ruleFinder.ruleStoppingValidator = orange.RuleValidator_LRS(
    alpha=0.01, min_coverage=10, max_rule_complexity=2)
learner.ruleFinder.ruleFilter = orange.RuleBeamFilter_Width(width=50)

cl = learner(data)
for r in cl.rules:
    print orngCN2.ruleToString(r)
    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()
import orngCN2

data = Orange.data.Table("titanic.tab")

# create learner
learner = orngCN2.CN2Learner()

cl = learner(data)
for r in cl.rules:
    print orngCN2.ruleToString(r)
print "*****"

learner = orngCN2.CN2UnorderedLearner()

learner.ruleFinder = Orange.core.RuleBeamFinder()
learner.ruleFinder.evaluator = orngCN2.mEstimate(m=50)

cl = learner(data)
for r in cl.rules:
    print orngCN2.ruleToString(r)
print "****"

learner = orngCN2.CN2SDUnorderedLearner()

learner.ruleFinder.ruleStoppingValidator = Orange.core.RuleValidator_LRS(alpha=0.01,min_coverage=10,max_rule_complexity = 2)
learner.ruleFinder.ruleFilter = Orange.core.RuleBeamFilter_Width(width = 50)

cl = learner(data)
for r in cl.rules:
    print orngCN2.ruleToString(r)
print "****"