Changeset 9407:0f81153e7fe3 in orange


Ignore:
Timestamp:
12/21/11 14:10:13 (2 years ago)
Author:
markotoplak
Branch:
default
Convert:
640cf0d2246da13d331e2e1ab8c3bf43e1fa1686
Message:

Merge orngAssoc to Orange.associate. References #733.

Location:
orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/associate/__init__.py

    r9405 r9407  
    385385    set([0, 2, 8, 10, 16, 17, 18]) 
    386386 
     387=============== 
     388Utilities 
     389=============== 
     390 
     391.. autofunction:: print_rules 
     392 
     393.. autofunction:: sort 
     394 
    387395""" 
    388  
    389  
    390  
    391396 
    392397from orange import \ 
     
    398403    ItemsetsSparseInducer 
    399404 
    400  
     405def print_rules(rules, ms = []): 
     406    """ 
     407    Print the rules. If ms is left empty, only the rules are printed. If ms 
     408    contains rules' attributes, e.g. ``["support", "confidence"]``, these are printed out as well. 
     409    """ 
     410    if ms: 
     411        print "\t".join([m[:4] for m in ms]) + "\trule" 
     412        for rule in rules: 
     413            print "\t".join(["%5.3f" % getattr(rule, m) for m in ms]) + "\t" + str(rule) 
     414    else: 
     415        for rule in rules: 
     416            print rule 
     417 
     418class __Cmp: 
     419    def __init__(self, ms): 
     420        self.ms = ms 
     421 
     422    def __call__(self, r1, r2):         
     423        for m in self.ms: 
     424            c = -cmp(getattr(r1, m), getattr(r2, m)) 
     425            if c: 
     426                return c 
     427        return 0 
     428 
     429def sort(rules, ms = ["support"]): 
     430    """ 
     431    Sort the rules according to the given criteria. The default key is "support"; list multiple keys in a list. 
     432    """ 
     433    rules.sort(__Cmp(ms)) 
  • orange/orngAssoc.py

    r6538 r9407  
    11# Provided only for backward compatibility. 
    2 # Don't use 
    32 
    43import orange 
     
    98AssociationRulesInduces = orange.AssociationRulesInducer 
    109 
    11 def printRules(rules, ms = []): 
    12     if ms: 
    13         print "\t".join([m[:4] for m in ms]) + "\trule" 
    14         for rule in rules: 
    15             print "\t".join(["%5.3f" % getattr(rule, m) for m in ms]) + "\t" + str(rule) 
    16     else: 
    17         for rule in rules: 
    18             print rule 
     10import Orange.associate 
    1911 
    20 class Cmp: 
    21     def __init__(self, ms): 
    22         self.ms = ms 
    23  
    24     def __call__(self, r1, r2):         
    25         for m in self.ms: 
    26             c = -cmp(getattr(r1, m), getattr(r2, m)) 
    27             if c: 
    28                 return c 
    29         return 0 
    30  
    31 def sort(rules, ms = ["support"]): 
    32     rules.sort(Cmp(ms)) 
     12printRules = Orange.associate.print_rules 
     13sort = Orange.associate.sort 
Note: See TracChangeset for help on using the changeset viewer.