Ignore:
Timestamp:
01/31/12 12:03:04 (2 years ago)
Author:
Miha Stajdohar <miha.stajdohar@…>
Branch:
default
rebase_source:
bc1f0880c5e12a6de0c26badda755e901dfab6ea
Message:

Added tree graph output signal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Classify/OWClassificationTree.py

    r9546 r9608  
    1111from exceptions import Exception 
    1212 
     13import Orange 
     14 
    1315import warnings 
    1416warnings.filterwarnings("ignore", ".*this class is not optimized for 'candidates' list and can be very slow.*", orange.KernelWarning, ".*orngTree", 34) 
     
    2224                    "preLeafInst", "preNodeInst", "preNodeMaj", 
    2325                    "preLeafInstP", "preNodeInstP", "preNodeMajP", 
    24                     "postMaj", "postMPruning", "postM",  
     26                    "postMaj", "postMPruning", "postM", 
    2527                    "limitDepth", "maxDepth"] 
    2628 
     
    2830    binarizationOpts = ["No binarization", "Exhaustive search for optimal split", "One value against others"] 
    2931 
    30     def __init__(self, parent=None, signalManager = None, name='Classification Tree'): 
    31         OWWidget.__init__(self, parent, signalManager, name, wantMainArea = 0, resizingEnabled = 0) 
     32    def __init__(self, parent=None, signalManager=None, name='Classification Tree'): 
     33        OWWidget.__init__(self, parent, signalManager, name, wantMainArea=0, resizingEnabled=0) 
    3234 
    3335        self.inputs = [("Data", ExampleTable, self.setData), ("Preprocess", PreprocessedLearner, self.setPreprocessor)] 
    34         self.outputs = [("Learner", orange.TreeLearner),("Classification Tree", orange.TreeClassifier)] 
     36        self.outputs = [("Learner", orange.TreeLearner), ("Classification Tree", orange.TreeClassifier), ("Classification Tree Graph", Orange.network.Graph)] 
    3537 
    3638        self.name = 'Classification Tree' 
     
    5254        qBox = OWGUI.widgetBox(self.controlArea, 'Attribute selection criterion') 
    5355 
    54         self.qMea = OWGUI.comboBox(qBox, self, "estim", items = [m[0] for m in self.measures], callback = self.measureChanged) 
     56        self.qMea = OWGUI.comboBox(qBox, self, "estim", items=[m[0] for m in self.measures], callback=self.measureChanged) 
    5557 
    56         b1 = OWGUI.widgetBox(qBox, orientation = "horizontal") 
     58        b1 = OWGUI.widgetBox(qBox, orientation="horizontal") 
    5759        OWGUI.separator(b1, 16, 0) 
    5860        b2 = OWGUI.widgetBox(b1) 
     
    6062        OWGUI.separator(b2) 
    6163        self.hbxRel2 = OWGUI.spin(b2, self, "relK", 1, 50, orientation="horizontal", label="Number of neighbours in ReliefF  ") 
    62   
     64 
    6365        OWGUI.separator(self.controlArea) 
    6466 
     
    8183 
    8284        OWGUI.separator(self.controlArea) 
    83         self.btnApply = OWGUI.button(self.controlArea, self, "&Apply", callback = self.setLearner, disabled=0, default=True) 
    84          
     85        self.btnApply = OWGUI.button(self.controlArea, self, "&Apply", callback=self.setLearner, disabled=0, default=True) 
     86 
    8587        OWGUI.rubber(self.controlArea) 
    86         self.resize(200,200) 
     88        self.resize(200, 200) 
    8789 
    88      
     90 
    8991    def sendReport(self): 
    9092        self.reportSettings("Learning parameters", 
     
    105107        self.preprocessor = preprocessor 
    106108        self.setLearner() 
    107          
     109 
    108110    def setLearner(self): 
    109111        if hasattr(self, "btnApply"): 
     
    113115        else: 
    114116            mDepth = {'maxDepth': self.maxDepth} 
    115         self.learner = orngTree.TreeLearner(measure = self.measures[self.estim][1], 
    116             reliefK = self.relK, reliefM = self.limitRef and self.relM or -1, 
    117             binarization = self.bin, 
    118             minExamples = self.preNodeInst and self.preNodeInstP, 
    119             minSubset = self.preLeafInst and self.preLeafInstP, 
    120             maxMajority = self.preNodeMaj and self.preNodeMajP/100.0 or 1.0, 
    121             sameMajorityPruning = self.postMaj, 
    122             mForPruning = self.postMPruning and self.postM, 
    123             storeExamples = 1, **mDepth) 
     117        self.learner = orngTree.TreeLearner(measure=self.measures[self.estim][1], 
     118            reliefK=self.relK, reliefM=self.limitRef and self.relM or -1, 
     119            binarization=self.bin, 
     120            minExamples=self.preNodeInst and self.preNodeInstP, 
     121            minSubset=self.preLeafInst and self.preLeafInstP, 
     122            maxMajority=self.preNodeMaj and self.preNodeMajP / 100.0 or 1.0, 
     123            sameMajorityPruning=self.postMaj, 
     124            mForPruning=self.postMPruning and self.postM, 
     125            storeExamples=1, **mDepth) 
    124126 
    125127        self.learner.name = self.name 
    126128        if self.preprocessor: 
    127129            self.learner = self.preprocessor.wrapLearner(self.learner) 
    128          
     130 
    129131        self.send("Learner", self.learner) 
    130132 
     
    140142            self.classifier = None 
    141143 
     144        tree_graph = None 
     145        if self.classifier is not None: 
     146            tree_graph = self.classifier.to_network() 
     147 
    142148        self.send("Classification Tree", self.classifier) 
     149        self.send("Classification Tree Graph", tree_graph) 
    143150 
    144151 
     
    149156        self.cbLimitRef.setEnabled(relief) 
    150157 
    151     def setData(self,data): 
     158    def setData(self, data): 
    152159        self.data = self.isDataWithClass(data, orange.VarTypes.Discrete, checkMissing=True) and data or None 
    153160        self.setLearner() 
     
    159166# Make sure that a sample data set (adult_sample.tab) is in the directory 
    160167 
    161 if __name__=="__main__": 
    162     a=QApplication(sys.argv) 
    163     ow=OWClassificationTree() 
     168if __name__ == "__main__": 
     169    a = QApplication(sys.argv) 
     170    ow = OWClassificationTree() 
    164171 
    165172    #d = orange.ExampleTable('adult_sample') 
Note: See TracChangeset for help on using the changeset viewer.