def __init__(self, evaluator=orange.RuleEvaluator_Entropy(), beamWidth=5, alpha=1.0, **kwds): self.__dict__.update(kwds) self.ruleFinder = orange.RuleBeamFinder() self.ruleFinder.ruleFilter = orange.RuleBeamFilter_Width( width=beamWidth) self.ruleFinder.evaluator = evaluator self.ruleFinder.validator = orange.RuleValidator_LRS(alpha=alpha)
def __init__(self, evaluator=orange.RuleEvaluator_Laplace(), beamWidth=5, alpha=1.0, **kwds): self.__dict__.update(kwds) self.ruleFinder = orange.RuleBeamFinder() self.ruleFinder.ruleFilter = orange.RuleBeamFilter_Width( width=beamWidth) self.ruleFinder.evaluator = evaluator self.ruleFinder.validator = orange.RuleValidator_LRS(alpha=alpha) self.ruleFinder.ruleStoppingValidator = orange.RuleValidator_LRS( alpha=1.0) self.ruleStopping = RuleStopping_apriori() self.dataStopping = orange.RuleDataStoppingCriteria_NoPositives()
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 orange 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:
def __init__(self, k): self.k = k self.counter = orange.newmetaid() self.weightID = orange.newmetaid() self.rbf = orange.RuleBeamFinder() self.rbf.evaluator = RuleEvaluator_WRAcc()
def __init__(self, m=2, opt_reduction=2, min_improved=1, min_improved_perc=0.0, nsampling=100, width=5, rule_sig=0.05, att_sig=0.5, max_rule_complexity=5, min_coverage=5, add_sub_rules=True, min_cl_sig=0.5, min_beta=0.0, set_prefix_rules=False, alternative_learner=None, **kwds): """ Parameters: EVC related: m ... m-estimate to be corrected with EVC (default 2) opt_reduction ... types of EVC correction; 0=no correction, 1=pessimistic, 2=normal (default 2) nsampling ... number of samples in estimating extreme value distribution (for EVC) (default 100) Probabilistic covering: min_improved ... minimal number of examples improved in probabilistic covering (default 1) min_improved_perc ... minimal percentage of covered examples that need to be improved (default 0.0) Beam search: width ... beam width (default 5) Rule Validation: rule_sig ... minimal rule significance (default 1.0) att_sig ... minimal attribute significance in rule (default 1.0) max_rule_complexity ... maximum number of conditions in rule (default 5) min_coverage ... minimal number of covered examples (default 5) Classifier (LCR) related: add_sub_rules ... add sub rules ? (default True) min_cl_sig ... minimal significance of beta in classifier (default 0.5) min_beta ... minimal beta value (default 0.0) set_prefix_rules ... should ordered prefix rules be added? (default False) alternative_learner ... use rule-learner as a correction method for other machine learning methods. (default None) """ # argument ID which is passed to abcn2 learner # two learners, learner with arguments and learners without self.ruleFinder = orange.RuleBeamFinder() self.ruleFilter = orange.RuleBeamFilter_Width(width=width) evdGet = orange.EVDistGetter_Standard() self.ruleFinder.evaluator = orange.RuleEvaluator_mEVC( m=m, evDistGetter=evdGet, min_improved=min_improved, min_improved_perc=min_improved_perc) self.ruleFinder.evaluator.returnExpectedProb = True self.ruleFinder.evaluator.optimismReduction = opt_reduction self.ruleFinder.evaluator.ruleAlpha = rule_sig self.ruleFinder.evaluator.attributeAlpha = att_sig self.ruleFinder.ruleStoppingValidator = orange.RuleValidator_LRS( alpha=1.0, min_quality=0., max_rule_complexity=max_rule_complexity - 1) self.ruleFinder.evaluator.validator = orange.RuleValidator_LRS( alpha=1.0, min_quality=0., min_coverage=min_coverage) self.coverAndRemove = CovererAndRemover_Prob() self.ruleStopping = None self.dataStopping = orange.RuleDataStoppingCriteria_NoPositives() self.N = nsampling self.add_sub_rules = add_sub_rules self.min_cl_sig = min_cl_sig self.min_beta = min_beta self.set_prefix_rules = set_prefix_rules self.alternativeLearner = alternative_learner self.__dict__.update(kwds)