source: orange/Orange/associate/__init__.py @ 9988:4e1229e347ca

Revision 9988:4e1229e347ca, 1.1 KB checked in by blaz <blaz.zupan@…>, 2 years ago (diff)

Polished discretization scripts.

Line 
1from orange import \
2    AssociationRule, \
3    AssociationRules, \
4    AssociationRulesInducer, \
5    AssociationRulesSparseInducer, \
6    ItemsetNodeProxy, \
7    ItemsetsSparseInducer
8
9def print_rules(rules, ms = []):
10    """
11    Print the rules. If ms is left empty, only the rules are printed. If ms
12    contains rules' attributes, e.g. ``["support", "confidence"]``, these are printed out as well.
13    """
14    if ms:
15        print "\t".join([m[:4] for m in ms]) + "\trule"
16        for rule in rules:
17            print "\t".join(["%5.3f" % getattr(rule, m) for m in ms]) + "\t" + str(rule)
18    else:
19        for rule in rules:
20            print rule
21
22class __Cmp:
23    def __init__(self, ms):
24        self.ms = ms
25
26    def __call__(self, r1, r2):       
27        for m in self.ms:
28            c = -cmp(getattr(r1, m), getattr(r2, m))
29            if c:
30                return c
31        return 0
32
33def sort(rules, ms = ["support"]):
34    """
35    Sort the rules according to the given criteria. The default key is "support"; list multiple keys in a list.
36    """
37    rules.sort(__Cmp(ms))
Note: See TracBrowser for help on using the repository browser.