source: orange/Orange/OrangeWidgets/Regression/OWRandomForestRegression.py @ 11628:0453b7a5b43b

Revision 11628:0453b7a5b43b, 1.7 KB checked in by Ales Erjavec <ales.erjavec@…>, 2 years ago (diff)

Added back single tree output using the simple tree converter.

Line 
1"""
2<name>Random Forest Regression</name>
3<description>Random forest regression.</description>
4<icon>icons/RandomForestRegression.svg</icon>
5<contact>Marko Toplak (marko.toplak(@at@)gmail.com)</contact>
6<priority>320</priority>
7<tags>bagging,ensemble</tags>
8
9"""
10
11from OWRandomForest import *
12
13class OWRandomForestRegression(OWRandomForest):
14    def __init__(self, parent=None, signalManager=None,
15                 title="Random forest regression"):
16        OWRandomForest.__init__(self, parent, signalManager, title)
17
18        self.inputs = [("Data", ExampleTable, self.setData),
19                       ("Preprocess", PreprocessedLearner, self.setPreprocessor)]
20
21        self.outputs = [("Learner", orange.Learner),
22                        ("Random Forest Classifier", orange.Classifier),
23                        ("Selected Tree", Orange.classification.tree.TreeClassifier)]
24
25    def setData(self, data):
26        if not self.isDataWithClass(data, orange.VarTypes.Continuous,
27                                    checkMissing=True):
28            data = None
29        self.data = data
30
31        self.streeEnabled(False)
32        if self.data:
33            learner = self.constructLearner()
34            self.progressBarInit()
35            learner.callback = lambda v: self.progressBarSet(100.0 * v)
36            try:
37                self.classifier = learner(self.data)
38                self.classifier.name = self.name
39                self.streeEnabled(True)
40            except Exception, (errValue):
41                self.error(str(errValue))
42                self.classifier = None
43            self.progressBarFinished()
44        else:
45            self.classifier = None
46
47        self.send("Random Forest Classifier", self.classifier)
Note: See TracBrowser for help on using the repository browser.