source: orange/orange/OrangeWidgets/Associate/OWItemsets.py @ 9546:2b6cc6f397fe

Revision 9546:2b6cc6f397fe, 3.2 KB checked in by ales_erjavec <ales.erjavec@…>, 2 years ago (diff)

Renamed widget channel names in line with the new naming rules/convention.
Added backwards compatibility in orngDoc loadDocument to enable loading of schemas saved before the change.

Line 
1"""
2<name>Itemsets</name>
3<description>Finds frequent itemsets in the data.</description>
4<icon>icons/Itemsets.png</icon>
5<contact>Janez Demsar (janez.demsar(@at@)fri.uni-lj.si)</contact>
6<priority>1000</priority>
7"""
8import orange
9from OWWidget import *
10import OWGUI
11
12class Itemsets(object):
13    def __init__(self, itemsets, data):
14        self.itemsets = itemsets
15        self.data = data
16       
17class OWItemsets(OWWidget):
18    settingsList = ["minSupport", "useSparseAlgorithm", "maxRules"]
19   
20    def __init__(self,parent=None, signalManager = None):
21        OWWidget.__init__(self, parent, signalManager, "Itemsets", wantMainArea = 0)
22
23        from OWItemsets import Itemsets
24        self.inputs = [("Data", ExampleTable, self.setData)]
25        self.outputs = [("Itemsets", Itemsets)]
26
27        self.minSupport = 60
28        self.maxRules = 10000
29        self.useSparseAlgorithm = False
30        self.loadSettings()
31
32        self.dataset = None
33
34        box = OWGUI.widgetBox(self.space, "Settings", addSpace = True)
35        OWGUI.checkBox(box, self, 'useSparseAlgorithm', 'Use algorithm for sparse data', tooltip="Use original Agrawal's algorithm")
36        OWGUI.widgetLabel(box, "Minimal support [%]")
37        OWGUI.hSlider(box, self, 'minSupport', minValue=1, maxValue=100, ticks=10, step = 1)
38        OWGUI.separator(box, 0, 0)
39        OWGUI.widgetLabel(box, 'Maximal number of rules')
40        OWGUI.hSlider(box, self, 'maxRules', minValue=10000, maxValue=100000, step=10000, ticks=10000, debuggingEnabled = 0)
41
42        OWGUI.button(self.space, self, "&Find Itemsets", self.findItemsets, default=True)
43
44        OWGUI.rubber(self.controlArea)
45        self.adjustSize()
46
47    def sendReport(self):
48        self.reportSettings("Settings",
49                            [("Algorithm", ["attribute data", "sparse data"][self.useSparseAlgorithm]),
50                             ("Minimal support", self.minSupport),
51                             ("Maximal number of rules", self.maxRules)])
52
53
54    def findItemsets(self):
55        self.error()
56        if self.dataset:
57            try:
58                if self.useSparseAlgorithm:
59                    self.itemsets = orange.AssociationRulesSparseInducer(support = self.minSupport/100., storeExamples = True).getItemsets(self.dataset)
60                else:
61                    self.itemsets = orange.AssociationRulesInducer(support = self.minSupport/100., storeExamples = True).getItemsets(self.dataset)
62                self.send("Itemsets", (self.dataset, self.itemsets))
63            except Exception, (errValue):
64                errValue = str(errValue)
65                if "non-discrete attributes" in errValue and not self.useSparseAlgorithm:
66                    errValue += "\nTry using the algorithm for sparse data"
67                self.error(str(errValue))
68                self.send("Itemsets", None)
69        else:
70            self.send("Itemsets", None)
71
72
73    def setData(self,dataset):
74        self.dataset = dataset
75        self.findItemsets()
76
77if __name__=="__main__":
78    a=QApplication(sys.argv)
79    ow=OWItemsets()
80#    a.setMainWidget(ow)
81    data = orange.ExampleTable("c:\\d\\ai\\orange\\doc\\datasets\\zoo")
82    ow.setData(data)
83    ow.show()
84    a.exec_()
85    ow.saveSettings()
86
Note: See TracBrowser for help on using the repository browser.