source: orange/orange/OrangeWidgets/Classify/OWEnsemble.py @ 9546:2b6cc6f397fe

Revision 9546:2b6cc6f397fe, 2.4 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>Ensemble</name>
3<description>Ensemble classification</description>
4<icons>icons/Ensemble.png</icons>
5<contact>Ales Erjavec (ales.erjavec(@at@)fri.uni-lj.si)</contact>
6<priority>330</priority>
7<keywords>ensemble, bagging, boosting, adaboost</keywords>
8
9"""
10
11from OWWidget import *
12
13import OWGUI
14
15import orange
16import orngEnsemble
17
18import os, sys
19
20
21class OWEnsemble(OWWidget):
22    settingsList = ["method", "t"]
23   
24    METHODS = [("Boosting", orngEnsemble.BoostedLearner),
25               ("Bagging", orngEnsemble.BaggedLearner)]
26   
27    def __init__(self, parent=None, signalManager=None, name="Ensemble"):
28        OWWidget.__init__(self, parent, signalManager, name, wantMainArea=False)
29       
30        self.inputs = [("Learner", orange.Learner, self.setLearner), ("Data", ExampleTable, self.setData)]
31        self.outputs = [("Learner", orange.Learner), ("Classifier", orange.Classifier)]
32       
33        self.method = 0
34        self.t = 10
35       
36        self.loadSettings()
37       
38        box = OWGUI.radioButtonsInBox(self.controlArea, self, "method", [name for name, _ in self.METHODS], box="Ensemble", callback=self.onChange)
39        i_box = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(box.buttons[0]))
40       
41        OWGUI.spin(i_box, self, "t", min=1, max=100, step=1, label="Number of created classifiers:")
42        OWGUI.rubber(self.controlArea)
43        OWGUI.button(self.controlArea, self, "&Apply", callback=self.commit)
44       
45        self.data = None
46        self.learner = None
47       
48        self.resize(100, 100)
49       
50    def setLearner(self, learner=None):
51        self.learner = learner
52       
53    def setData(self, data):
54        self.data = data
55       
56    def handleNewSignals(self):
57        self.commit()
58       
59    def onChange(self):
60        pass
61   
62    def commit(self):
63        wrapped = None
64        if self.learner:
65            wrapped = self.METHODS[self.method][1](self.learner, t=self.t)
66            self.send("Learner", wrapped)
67           
68        if self.data and wrapped:
69            classifier = wrapped(self.data)
70            self.send("Classifier", classifier)
71           
72if __name__ == "__main__":
73    app = QApplication(sys.argv)
74    w = OWEnsemble()
75    w.setLearner(orange.BayesLearner())
76    w.setData(orange.ExampleTable("../../doc/datasets/iris"))
77    w.show()
78    app.exec_()
79           
80       
81       
82         
Note: See TracBrowser for help on using the repository browser.