def to_rule(self, table, cont_dists=None, disc_dists=None): """ @param cols list of attribute names """ if not self.rule: domain = table.domain attrnames = [attr.name for attr in domain] cont_dists = cont_dists or dict(zip(attrnames, Orange.statistics.basic.Domain(table))) disc_dists = disc_dists or dict(zip(attrnames, Orange.statistics.distribution.Domain(table))) conds = [] for col, bound in zip(self.cols, zip(*self.bbox)): attr = domain[col] pos = domain.index(attr) table_bound = cont_dists[attr.name] minv, maxv = max(table_bound.min, bound[0]), min(table_bound.max, bound[1]) if maxv - minv > 0.9 * (table_bound.max-table_bound.min): continue conds.append( orange.ValueFilter_continuous( position=pos, max=bound[1], min=bound[0] ) ) for disc_name, vidxs in self.discretes.iteritems(): attr = domain[disc_name] disc_pos = domain.index(attr) vals = [orange.Value(attr, attr.values[int(vidx)]) for vidx in vidxs if int(vidx) < len(attr.values)] if not vals or len(vals) == len(disc_dists[attr.name]): continue conds.append( orange.ValueFilter_discrete( position = disc_pos, values=vals ) ) rule = SDRule(table, None, conditions=conds) self.rule = rule rule = self.rule rule.quality = rule.score = self.error rule.inf_state = self.inf_state rule.c_range = self.c_range return rule
if not isnumerical: try: val = float(val) except: val = quote_sql_str(val) return '%s %s %s' % (attr, cmp, val) #return '%s is not null and %s %s %s' % (attr, attr, cmp, val) if __name__ == '__main__': from learners.cn2sd.rule import SDRule d = Orange.data.Table('iris') rule = SDRule(d, d.domain.classVar.values[0]) rule = rule.cloneAndAddContCondition(d.domain[0], 4, 5) print sdrule_to_clauses(rule) exit() import sys import random import time import matplotlib import matplotlib.pyplot as plt sys.path.append('.') from matplotlib.backends.backend_pdf import PdfPages from collections import Counter