예제 #1
0
 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
예제 #2
0
 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")
예제 #3
0
 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
예제 #4
0
 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)