Orange Forum • View topic - association rule question for a new orange user

association rule question for a new orange user

A place to ask questions about methods in Orange and how they are used and other general support.

association rule question for a new orange user

Postby Guest » Sat Jul 22, 2006 20:38

Ok, so I'm an Orange and Python newbie.

Can anyone tell me why the example for association rules is not working?

Output-

[size=9]>>> 87 rules with support higher than or equal to 0.400 found.

Traceback (most recent call last):
File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 307, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
File "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 592, in run
exec cmd in globals, locals
File "C:\orange\assoc1.py", line 18, in ?
orngAssoc.sort(rules, ["support", "confidence"])
AttributeError: 'module' object has no attribute 'sort'
>>>
[/size]

Code-

# Description: Creates a list of association rules, selects five rules and prints them out
# Category: description
# Uses: imports-85
# Classes: orngAssoc.build, Preprocessor_discretize, EquiNDiscretization
# Referenced: assoc.htm

import orange, orngAssoc

data = orange.ExampleTable("imports-85")
data = orange.Preprocessor_discretize(data, \
method=orange.EquiNDiscretization(numberOfIntervals=3))
data = data.select(range(10))

rules = orange.AssociationRulesInducer(data, support=0.4)

print "%i rules with support higher than or equal to %5.3f found.\n" % (len(rules), 0.4)

orngAssoc.sort(rules, ["support", "confidence"])

orngAssoc.printRules(rules[:5], ["support", "confidence"])
print

del rules[:3]
orngAssoc.printRules(rules[:5], ["support", "confidence"])
print

Postby Janez » Sat Jul 22, 2006 21:26

We've been changing this module lately (OK, we made a mess). If your version misses the function sort, please add it yourself - paste the following to the module:

Code: Select all
class Cmp:
    def __init__(self, ms):
        self.ms = ms

    def __call__(self, r1, r2):       
        for m in self.ms:
            c = -cmp(getattr(r1, m), getattr(r2, m))
            if c:
                return c
        return 0

def sort(rules, ms = ["support"]):
    rules.sort(Cmp(ms))


Return to Questions & Support