Changeset 3632:61f265f1b750 in orange


Ignore:
Timestamp:
05/08/07 09:38:53 (7 years ago)
Author:
markotoplak
Branch:
default
Convert:
b8463363a77fd01eb2037b6f6fe90858537a0178
Message:

Modified random forests widget so that is can output a single tree.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWRandomForests.py

    r3577 r3632  
    1313 
    1414class OWRandomForests(OWWidget): 
    15     settingsList = ["name", "trees", "attributes", "attributesP", "preNodeInst", "preNodeInstP", "limitDepth", "limitDepthP", "rseed" ] 
     15    settingsList = ["name", "trees", "attributes", "attributesP", "preNodeInst", "preNodeInstP", "limitDepth", "limitDepthP", "rseed", "outtree" ] 
    1616 
    1717    def __init__(self, parent=None, signalManager = None, name='Random Forests'): 
     
    1919 
    2020        self.inputs = [("Examples", ExampleTable, self.setData)] 
    21         self.outputs = [("Learner", orange.Learner),("Random Forests Classifier", orange.Classifier)] 
     21        self.outputs = [("Learner", orange.Learner),("Random Forests Classifier", orange.Classifier),("Choosen Tree", orange.TreeClassifier) ] 
    2222 
    2323        self.name = 'Random Forests' 
     
    3030    self.limitDepthP = 3 
    3131    self.rseed = 0 
     32    self.outtree = 0 
     33     
     34 
     35    self.maxTrees = 10000 
    3236 
    3337        self.loadSettings() 
     
    3539        self.data = None 
    3640        self.preprocessor = None 
    37         self.setLearner() 
    3841 
    3942        OWGUI.lineEdit(self.controlArea, self, 'name', box='Learner/Classifier Name', tooltip='Name to be used by other widgets to identify your learner/classifier.') 
     
    4245 
    4346        self.bBox = QVGroupBox(self.controlArea) 
    44         self.bBox.setTitle('Basic properties') 
     47        self.bBox.setTitle('Basic Properties') 
    4548 
    46         self.treesBox = OWGUI.spin(self.bBox, self, "trees", 1, 10000, orientation="horizontal", label="Number of trees in forest  ") 
     49        self.treesBox = OWGUI.spin(self.bBox, self, "trees", 1, self.maxTrees, orientation="horizontal", label="Number of trees in forest  ") 
    4750    self.attributesBox, self.attributesPBox = OWGUI.checkWithSpin(self.bBox, self, "Consider exactly", 1, 10000, "attributes", "attributesP", " random attributes at each split.") 
    4851        self.rseedBox = OWGUI.spin(self.bBox, self, "rseed", 0, 100000, orientation="horizontal", label="Seed for random generator ") 
     
    5558    self.limitDepthBox, self.limitDepthPBox = OWGUI.checkWithSpin(self.pBox, self, "Maximum depth of individual trees  ", 1, 1000, "limitDepth", "limitDepthP", "") 
    5659        self.preNodeInstBox, self.preNodeInstPBox = OWGUI.checkWithSpin(self.pBox, self, "Stop splitting nodes with ", 1, 1000, "preNodeInst", "preNodeInstP", " or fewer instances") 
     60 
    5761        OWGUI.separator(self.controlArea) 
    58         self.btnApply = OWGUI.button(self.controlArea, self, "&Apply Changes", callback = self.setLearner, disabled=0) 
     62 
     63        #self.sBox = QVGroupBox(self.controlArea) 
     64        #self.sBox.setTitle('Single Tree Output') 
     65     
     66    self.streesBox = OWGUI.spin(self.controlArea, self, "outtree", -1, self.maxTrees, orientation="horizontal", label="Index of tree on the output ", callback=[self.period, self.extree]) 
     67    #self.streesBox.setDisabled(True) 
     68    self.streeEnabled(False) 
     69 
     70    OWGUI.separator(self.controlArea) 
     71 
     72    self.btnApply = OWGUI.button(self.controlArea, self, "&Apply Changes", callback = self.setLearner, disabled=0) 
    5973 
    6074        self.resize(100,200) 
     75 
     76    self.setLearner() 
     77 
     78    def period(self): 
     79    if self.outtree == -1: self.outtree = self.claTrees-1 
     80    elif self.outtree >= self.claTrees: self.outtree = 0 
     81 
     82    def extree(self): 
     83    self.send("Choosen Tree", self.classifier.classifiers[self.outtree]) 
     84 
     85    def streeEnabled(self, status): 
     86    if status: 
     87        self.claTrees = self.trees 
     88        self.streesBox.setDisabled(False) 
     89        self.period() 
     90        self.extree() 
     91    else: 
     92        #a = 1 
     93        self.streesBox.setDisabled(True) 
    6194 
    6295    def pbchange(self, val): 
     
    81114        else: self.learner.learner.stop.minExamples = 0 
    82115 
     116    self.learner.learner.storeExamples = 1 
     117    self.learner.learner.storeNodeClassifier = 1 
     118    self.learner.learner.storeContigencies = 1 
     119    self.learner.learner.storeDistributions = 1 
     120 
    83121    if self.limitDepth: self.learner.learner.maxDepth = self.limitDepthP 
    84122 
     
    92130                self.classifier = self.learner(self.data) 
    93131                self.classifier.name = self.name 
     132        self.streeEnabled(True) 
    94133            except Exception, (errValue): 
    95134                self.error(str(errValue)) 
    96135                self.classifier = None 
     136        self.streeEnabled(False) 
    97137        else: 
    98             self.classifier = None 
    99  
     138        self.classifier = None 
     139        self.streeEnabled(False) 
    100140 
    101141    self.progressBarFinished() 
Note: See TracChangeset for help on using the changeset viewer.