Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/extend-widgets/rst/OWLearningCurveA.py

    r11085 r11593  
    22<name>Learning Curve (A)</name> 
    33<description>Takes a data set and a set of learners and shows a learning curve in a table</description> 
    4 <icon>icons/LearningCurveA.png</icon> 
     4<icon>icons/LearningCurve.svg</icon> 
    55<priority>1000</priority> 
    66""" 
    77 
     8import Orange 
     9 
    810from OWWidget import * 
    9 import OWGUI, orngTest, orngStat 
     11import OWGUI 
    1012 
    1113class OWLearningCurveA(OWWidget): 
    1214    settingsList = ["folds", "steps", "scoringF", "commitOnChange"] 
    13      
     15 
    1416    def __init__(self, parent=None, signalManager=None): 
    1517        OWWidget.__init__(self, parent, signalManager, 'LearningCurveA') 
    1618 
    17         self.inputs = [("Data", ExampleTable, self.dataset), 
    18                        ("Learner", orange.Learner, self.learner, Multiple)] 
    19          
     19        self.inputs = [("Data", Orange.data.Table, self.dataset), 
     20                       ("Learner", Orange.core.Learner, self.learner, 
     21                        Multiple)] 
     22 
    2023        self.folds = 5     # cross validation folds 
    2124        self.steps = 10    # points in the learning curve 
     
    2326        self.commitOnChange = 1 # compute curve on any change of parameters 
    2427        self.loadSettings() 
    25         self.setCurvePoints() # sets self.curvePoints, self.steps equidistantpoints from 1/self.steps to 1 
    26         self.scoring = [("Classification Accuracy", orngStat.CA), ("AUC", orngStat.AUC), ("BrierScore", orngStat.BrierScore), ("Information Score", orngStat.IS), ("Sensitivity", orngStat.sens), ("Specificity", orngStat.spec)] 
     28        self.setCurvePoints() # sets self.curvePoints, self.steps equidistant points from 1/self.steps to 1 
     29        self.scoring = [("Classification Accuracy", Orange.evaluation.scoring.CA), 
     30                        ("AUC", Orange.evaluation.scoring.AUC), 
     31                        ("BrierScore", Orange.evaluation.scoring.Brier_score), 
     32                        ("Information Score", Orange.evaluation.scoring.IS), 
     33                        ("Sensitivity", Orange.evaluation.scoring.Sensitivity), 
     34                        ("Specificity", Orange.evaluation.scoring.Specificity)] 
    2735        self.learners = [] # list of current learners from input channel, tuples (id, learner) 
    2836        self.data = None   # data on which to construct the learning curve 
     
    3644 
    3745        OWGUI.separator(self.controlArea) 
     46 
    3847        box = OWGUI.widgetBox(self.controlArea, "Evaluation Scores") 
    3948        scoringNames = [x[0] for x in self.scoring] 
    40         OWGUI.comboBox(box, self, "scoringF", items=scoringNames, callback=self.computeScores) 
     49        OWGUI.comboBox(box, self, "scoringF", items=scoringNames, 
     50                       callback=self.computeScores) 
    4151 
    4252        OWGUI.separator(self.controlArea) 
     53 
    4354        box = OWGUI.widgetBox(self.controlArea, "Options") 
    44         OWGUI.spin(box, self, 'folds', 2, 100, step=1, label='Cross validation folds:  ', 
     55        OWGUI.spin(box, self, 'folds', 2, 100, step=1, 
     56                   label='Cross validation folds:  ', 
    4557                   callback=lambda: self.computeCurve(self.commitOnChange)) 
    46         OWGUI.spin(box, self, 'steps', 2, 100, step=1, label='Learning curve points:  ', 
    47                    callback=[self.setCurvePoints, lambda: self.computeCurve(self.commitOnChange)]) 
    48  
     58        OWGUI.spin(box, self, 'steps', 2, 100, step=1, 
     59                   label='Learning curve points:  ', 
     60                   callback=[self.setCurvePoints, 
     61                             lambda: self.computeCurve(self.commitOnChange)]) 
    4962        OWGUI.checkBox(box, self, 'commitOnChange', 'Apply setting on any change') 
    50         self.commitBtn = OWGUI.button(box, self, "Apply Setting", callback=self.computeCurve, disabled=1) 
     63        self.commitBtn = OWGUI.button(box, self, "Apply Setting", 
     64                                      callback=self.computeCurve, disabled=1) 
     65 
     66        OWGUI.rubber(self.controlArea) 
    5167 
    5268        # table widget 
    53         self.table = OWGUI.table(self.mainArea, selectionMode=QTableWidget.NoSelection) 
    54                  
     69        self.table = OWGUI.table(self.mainArea, 
     70                                 selectionMode=QTableWidget.NoSelection) 
     71 
    5572        self.resize(500,200) 
    5673 
    5774    ##############################################################################     
    58     # slots: handle input signals         
     75    # slots: handle input signals 
    5976 
    6077    def dataset(self, data): 
     
    6885            self.curves = [] 
    6986            self.scores = [] 
    70         self.commitBtn.setEnabled(self.data<>None) 
     87        self.commitBtn.setEnabled(self.data is not None) 
    7188 
    7289    def learner(self, learner, id=None): 
     
    107124            self.infob.setText("No learners.") 
    108125        self.commitBtn.setEnabled(len(self.learners)) 
    109 ##        if len(self.scores): 
     126 
    110127        if self.data: 
    111128            self.setTable() 
     
    130147    def getLearningCurve(self, learners):    
    131148        pb = OWGUI.ProgressBar(self, iterations=self.steps*self.folds) 
    132         curve = orngTest.learningCurveN(learners, self.data, folds=self.folds, proportions=self.curvePoints, callback=pb.advance) 
     149        curve = Orange.evaluation.testing.learning_curve_n( 
     150            learners, self.data, folds=self.folds, 
     151            proportions=self.curvePoints, callback=pb.advance) 
    133152        pb.finish() 
    134153        return curve 
    135154 
    136155    def setCurvePoints(self): 
    137         self.curvePoints = [(x+1.)/self.steps for x in range(self.steps)] 
     156        self.curvePoints = [(x + 1.)/self.steps for x in range(self.steps)] 
    138157 
    139158    def setTable(self): 
     
    154173            self.table.setColumnWidth(i, 80) 
    155174 
    156 ############################################################################## 
    157 # Test the widget, run from prompt 
    158175 
    159176if __name__=="__main__": 
     
    162179    ow.show() 
    163180     
    164     l1 = orange.BayesLearner() 
     181    l1 = Orange.classification.bayes.NaiveLearner() 
    165182    l1.name = 'Naive Bayes' 
    166183    ow.learner(l1, 1) 
    167184 
    168     data = orange.ExampleTable('iris.tab') 
     185    data = Orange.data.Table('iris.tab') 
    169186    ow.dataset(data) 
    170187 
    171     l2 = orange.BayesLearner() 
     188    l2 = Orange.classification.bayes.NaiveLearner() 
    172189    l2.name = 'Naive Bayes (m=10)' 
    173     l2.estimatorConstructor = orange.ProbabilityEstimatorConstructor_m(m=10) 
    174     l2.conditionalEstimatorConstructor = orange.ConditionalProbabilityEstimatorConstructor_ByRows(estimatorConstructor = orange.ProbabilityEstimatorConstructor_m(m=10)) 
     190    l2.estimatorConstructor = Orange.statistics.estimate.M(m=10) 
     191    l2.conditionalEstimatorConstructor = \ 
     192        Orange.statistics.estimate.ConditionalByRows( 
     193            estimatorConstructor = Orange.statistics.estimate.M(m=10)) 
    175194    ow.learner(l2, 2) 
    176195 
    177     import orngTree 
    178     l4 = orngTree.TreeLearner(minSubset=2) 
     196    l4 = Orange.classification.tree.TreeLearner(minSubset=2) 
    179197    l4.name = "Decision Tree" 
    180198    ow.learner(l4, 4) 
Note: See TracChangeset for help on using the changeset viewer.