def ruleText(self, rule): text = orngCN2.ruleToString(rule, showDistribution=False) p = re.compile(r"[0-9]\.[0-9]+") text = p.sub(lambda match: "%.2f" % float(match.group()[0]), text) text = text.replace("AND", "AND\n ") text = text.replace("THEN", "\nTHEN") return text
def saveRules(self): fileName = str( QFileDialog.getSaveFileName(self, "Rules", "Rules.txt", ".txt")) try: f = open(fileName, "w") except: return for r in self.rules: f.write(orngCN2.ruleToString(r) + "\n")
def selectAttributes(self): import sets selected = [] for r in self.selRect: string = orngCN2.ruleToString( r.rule)[2:].strip(" ").split("THEN")[0] list = string.split("AND") for l in list: s = re.split("[=<>]", l.strip(" ")) selected.append(s[0]) selected = reduce(lambda l, r: (r in l) and l or l + [r], selected, []) return selected
def ruleText(self, r): str = orngCN2.ruleToString(r) list = re.split("([0-9.]*)", str) for i in range(len(list)): try: f = float(list[i]) list[i] = "%.3f" % f t = int(list[i]) list[i] = str(t) except: pass str = "".join(list) list = re.split("<[0-9., ]*>$", str) str = list[0] str = "AND\n ".join(str.split("AND")) str = "\nTHEN".join(str.split("THEN")) return str
# Description: Demonstrates the use of orngABCN2 rules # Category: classification, rules # Classes: ABCN2, ABCN2Ordered, ABCN2M # Uses: titanic.tab import orange import orngABCN2 import orngCN2 data = orange.ExampleTable("titanic.tab") # create learner learner = orngABCN2.ABCN2() cl = learner(data) for r in cl.rules: print orngCN2.ruleToString(r) print "*****" learner = orngABCN2.ABCN2Ordered() cl = learner(data) for r in cl.rules: print orngCN2.ruleToString(r) print "*****" learner = orngABCN2.ABCN2M() cl = learner(data) for r in cl.rules: print orngCN2.ruleToString(r) print "*****"
# Description: Demonstrates the use of orngCN2 rules # Category: classification, rules # Classes: CN2Learner, CN2UnorderedLearner, CN2UnorderedLearner # Uses: titanic.tab import Orange 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)