Changeset 78:6d9fc54e06d8 in orange


Ignore:
Timestamp:
04/22/03 17:16:36 (10 years ago)
Author:
tomazc <tomazc@…>
Branch:
default
Convert:
fcb8fb478392a8e4488711ed65f8606c0c62fc00
Message:

no message

Location:
orange
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/OWCalibrationPlot.py

    r71 r78  
    382382    owdm.saveSettings() 
    383383 
     384 
  • orange/OrangeWidgets/OWROC.py

    r66 r78  
    6565        self.splitByIterations = None 
    6666        self.VTAsamples = 10 ## vertical threshold averaging, number of samples 
    67         self.FPcost = 500 
    68         self.FNcost = 500 
    69         self.pvalue = 400 ##0.400 
     67        self.FPcost = 500.0 
     68        self.FNcost = 500.0 
     69        self.pvalue = 400.0 ##0.400 
    7070 
    7171        self.performanceLineSymbol = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.color0), QPen(self.black), QSize(7,7)) 
     
    7373 
    7474        self.removeCurves() 
     75 
     76    def computeCurve(self, res, classIndex=-1, keepConcavities=1): 
     77        return orngEval.TCcomputeROC(res, classIndex, keepConcavities) 
    7578 
    7679    def setNumberOfClassifiersIterationsAndClassifierColors(self, classifierNames, iterationsNum, classifierColor): 
     
    133136        self.showIterations = [] 
    134137        self.showConvexCurves = 0 
    135         self.showROCconvexHull = 0 
     138        self.showConvexHull = 0 
    136139        self.showPerformanceLine = 0 
    137140        self.showDiagonal = 0 
     
    154157        self.classifierConvexHullData = [] 
    155158        self.hullCurveDataForPerfLine = [] ## for performance analysis 
    156         self.performanceXYpointText = {} ## best classifiers and their cut-off points for each point on convex hull (key is point (x, y) on hull) 
    157159 
    158160        ## diagonal curve 
     
    200202        for isplit in splitByIterations: 
    201203            # unmodified ROC curve 
    202             curves = orngEval.TCcomputeROC(isplit, self.targetClass, 1) 
     204            curves = self.computeCurve(isplit, self.targetClass, 1) 
    203205            self.setIterationCurves(iteration, curves) 
    204206 
    205207            # convex ROC curve 
    206             curves = orngEval.TCcomputeROC(isplit, self.targetClass, 0) 
     208            curves = self.computeCurve(isplit, self.targetClass, 0) 
    207209            self.setIterationConvexCurves(iteration, curves) 
    208210            iteration += 1 
     
    245247                self.curve(self.classifierIterationConvexCKeys[cNum][iNum]).setEnabled(b) 
    246248 
    247         chb = (showSomething) and (self.averagingMethod == None) and self.showROCconvexHull 
     249        chb = (showSomething) and (self.averagingMethod == None) and self.showConvexHull 
    248250        curve =  self.curve(self.classifierConvexHullCKey) 
    249251        if curve <> None: curve.setEnabled(chb) 
    250252 
    251         chb = (showSomething) and (self.averagingMethod == 'merge') and self.showROCconvexHull 
     253        chb = (showSomething) and (self.averagingMethod == 'merge') and self.showConvexHull 
    252254        curve =  self.curve(self.mergedConvexHullCKey) 
    253255        if curve <> None: curve.setEnabled(chb) 
    254256 
    255         chb = (showSomething) and (self.averagingMethod == 'vertical') and self.showROCconvexHull 
     257        chb = (showSomething) and (self.averagingMethod == 'vertical') and self.showConvexHull 
    256258        curve =  self.curve(self.verticalConvexHullCKey) 
    257259        if curve <> None: curve.setEnabled(chb) 
    258260 
    259         chb = (showSomething) and (self.averagingMethod == 'threshold') and self.showROCconvexHull 
     261        chb = (showSomething) and (self.averagingMethod == 'threshold') and self.showConvexHull 
    260262        curve =  self.curve(self.thresholdConvexHullCKey) 
    261263        if curve <> None: curve.setEnabled(chb) 
     
    271273        self.update() 
    272274 
    273     def setShowConvexROCcurves(self, b): 
     275    def setShowConvexCurves(self, b): 
    274276        self.showConvexCurves = b 
    275277        self.updateCurveDisplay() 
    276278 
    277     def setShowROCconvexHull(self, b): 
    278         self.showROCconvexHull = b 
     279    def setShowConvexHull(self, b): 
     280        self.showConvexHull = b 
    279281        self.updateCurveDisplay() 
    280282 
     
    309311        self.mergedConvexHullData = [] 
    310312        if len(mergedIterations.results) > 0: 
    311             curves = orngEval.TCcomputeROC(mergedIterations, self.targetClass, 1) 
    312             convexCurves = orngEval.TCcomputeROC(mergedIterations, self.targetClass, 0) 
     313            curves = self.computeCurve(mergedIterations, self.targetClass, 1) 
     314            convexCurves = self.computeCurve(mergedIterations, self.targetClass, 0) 
    313315            classifier = 0 
    314316            for c in curves: 
     
    431433 
    432434        self.hullCurveDataForPerfLine = TCconvexHull(hullData) # keep data about curve for performance line drawing 
    433         self.performanceXYpointText = {} ## best classifiers and their cut-off points for each point on convex hull (key is point (x, y) on hull) 
    434         x = [] 
    435         y = [] 
    436         for (px, py, pf) in self.hullCurveDataForPerfLine: 
    437             x.append(px) 
    438             y.append(py) 
    439             s = ["%1.3f %s" % (pfscore, self.classifierNames[cNum]) for (cNum, pfscore) in pf] 
    440             self.performanceXYpointText[ str((px, py)) ] = s 
     435        x = [px for (px, py, pf) in self.hullCurveDataForPerfLine] 
     436        y = [py for (px, py, pf) in self.hullCurveDataForPerfLine] 
    441437        self.setCurveData(self.mergedConvexHullCKey, x, y) 
    442438 
     
    469465    ## performance line 
    470466    def calcUpdatePerformanceLine(self): 
    471         m = (float(self.FPcost) * float(1.0 - self.pvalue)) / (float(self.FNcost) * float(self.pvalue)) 
     467        m = (self.FPcost*(1.0 - self.pvalue)) / (self.FNcost*self.pvalue) 
    472468 
    473469        ## put the iso-performance line in point (0.0, 1.0) 
     
    479475        firstp = 1 
    480476        mind = 0.0 
    481         bestfscore = 'n/a' 
    482477        a = (x0*y1 - x1*y0) 
    483478        closestpoints = [] 
    484         for (x, y, fscore) in self.hullCurveDataForPerfLine: 
     479        for (x, y, fscorelist) in self.hullCurveDataForPerfLine: 
    485480            d = ((y0 - y1)*x + (x1 - x0)*y + a) / d01 
    486481            d = abs(d) 
    487482            if firstp or d < mind: 
    488                 mind, bestfscore, firstp = d, fscore, 0 
    489                 closestpoints = [(x, y)] 
     483                mind, firstp = d, 0 
     484                closestpoints = [(x, y, fscorelist)] 
    490485            else: 
    491486                if abs(d - mind) <= 0.0001: ## close enough 
    492                     closestpoints.append( (x, y) ) 
     487                    closestpoints.append( (x, y, fscorelist) ) 
    493488 
    494489        ## now draw the closest line to the curve 
     
    498493        lpy = [] 
    499494        first = 1 
    500         for (x, y) in closestpoints: 
     495        for (x, y, fscorelist) in closestpoints: 
    501496            if first: 
    502497                first = 0 
     
    507502            px = x 
    508503            py = y 
    509             for s in self.performanceXYpointText.get(str((x, y)), []): 
     504            for (cNum, threshold) in fscorelist: 
     505                s = "%1.3f %s" % (threshold, self.classifierNames[cNum]) 
    510506                py = py - 0.05 
    511507                mkey = self.insertMarker(s) 
     
    523519 
    524520    def costChanged(self, FPcost, FNcost): 
    525         self.FPcost = FPcost 
    526         self.FNcost = FNcost 
     521        self.FPcost = float(FPcost) 
     522        self.FNcost = float(FNcost) 
    527523        self.calcUpdatePerformanceLine() 
    528524 
    529525    def pChanged(self, pvalue): 
    530         self.pvalue = pvalue 
     526        self.pvalue = float(pvalue) 
    531527        self.calcUpdatePerformanceLine() 
    532528 
     
    536532        self.update() 
    537533 
    538     def setROCcurveWidth(self, v): 
     534    def setCurveWidth(self, v): 
    539535        for cNum in range(len(self.showClassifiers)): 
    540536            self.setCurvePen(self.mergedCKeys[cNum], QPen(self.classifierColor[cNum], v)) 
     
    545541        self.update() 
    546542 
    547     def setROCconvexCurveWidth(self, v): 
     543    def setConvexCurveWidth(self, v): 
    548544        for cNum in range(len(self.showClassifiers)): 
    549545            self.setCurvePen(self.mergedConvexCKeys[cNum], QPen(self.classifierColor[cNum], v)) 
     
    556552        self.updateCurveDisplay() 
    557553 
    558     def setROCconvexHullCurveWidth(self, v): 
     554    def setConvexHullCurveWidth(self, v): 
    559555        self.convexHullPen.setWidth(v) 
    560556        self.setCurvePen(self.mergedConvexHullCKey, self.convexHullPen) 
     
    637633 
    638634class OWROC(OWWidget): 
    639     settingsList = ["PointWidth", "ROCcurveWidth", "ROCconvexCurveWidth", "ShowDiagonal", 
    640                     "ROCconvexHullCurveWidth", "HullColor"] 
     635    settingsList = ["PointWidth", "CurveWidth", "ConvexCurveWidth", "ShowDiagonal", 
     636                    "ConvexHullCurveWidth", "HullColor"] 
    641637    def __init__(self,parent=None): 
    642638        "Constructor" 
     
    651647        #set default settings 
    652648        self.PointWidth = 7 
    653         self.ROCcurveWidth = 3 
    654         self.ROCconvexCurveWidth = 1 
     649        self.CurveWidth = 3 
     650        self.ConvexCurveWidth = 1 
    655651        self.ShowDiagonal = TRUE 
    656         self.ROCconvexHullCurveWidth = 3 
     652        self.ConvexHullCurveWidth = 3 
    657653        self.HullColor = str(Qt.yellow.name()) 
    658654 
     
    695691        #connect GUI controls of options in options dialog to settings 
    696692        self.connect(self.options.pointWidthSlider, SIGNAL("valueChanged(int)"), self.setPointWidth) 
    697         self.connect(self.options.lineWidthSlider, SIGNAL("valueChanged(int)"), self.setROCcurveWidth) 
    698         self.connect(self.options.convexWidthSlider, SIGNAL("valueChanged(int)"), self.setROCconvexCurveWidth) 
     693        self.connect(self.options.lineWidthSlider, SIGNAL("valueChanged(int)"), self.setCurveWidth) 
     694        self.connect(self.options.convexWidthSlider, SIGNAL("valueChanged(int)"), self.setConvexCurveWidth) 
    699695        self.connect(self.options.showDiagonalQCB, SIGNAL("toggled(bool)"), self.setShowDiagonal) 
    700         self.connect(self.options.hullWidthSlider, SIGNAL("valueChanged(int)"), self.setROCconvexHullCurveWidth) 
     696        self.connect(self.options.hullWidthSlider, SIGNAL("valueChanged(int)"), self.setConvexHullCurveWidth) 
    701697        self.connect(self.options, PYSIGNAL("hullColorChange(QColor &)"), self.setHullColor) 
    702698 
     
    724720 
    725721        # show convex ROC curves 
    726         self.convexROCcurvesQCB = QCheckBox("convex ROC curves", self.classifiersQVGB) ## !!! only in None and Merge average mode 
    727         self.connect(self.convexROCcurvesQCB, SIGNAL("stateChanged(int)"), self.setShowConvexROCcurves) 
     722        self.convexCurvesQCB = QCheckBox("convex ROC curves", self.classifiersQVGB) ## !!! only in None and Merge average mode 
     723        self.connect(self.convexCurvesQCB, SIGNAL("stateChanged(int)"), self.setShowConvexCurves) 
    728724 
    729725        # show ROC convex hull 
    730         self.ROCconvexhullQCB = QCheckBox("ROC convex hull", self.classifiersQVGB) 
    731         self.connect(self.ROCconvexhullQCB, SIGNAL("stateChanged(int)"), self.setShowROCconvexHull) 
     726        self.convexhullQCB = QCheckBox("ROC convex hull", self.classifiersQVGB) 
     727        self.connect(self.convexhullQCB, SIGNAL("stateChanged(int)"), self.setShowConvexHull) 
    732728 
    733729        ## test set selection (testSetsQLB) 
     
    783779            g.setPointWidth(v) 
    784780 
    785     def setROCcurveWidth(self, v): 
    786         self.ROCcurveWidth = v 
    787         for g in self.graphs: 
    788             g.setROCcurveWidth(v) 
    789  
    790     def setROCconvexCurveWidth(self, v): 
    791         self.ROCconvexCurveWidth = v 
    792         for g in self.graphs: 
    793             g.setROCconvexCurveWidth(v) 
     781    def setCurveWidth(self, v): 
     782        self.CurveWidth = v 
     783        for g in self.graphs: 
     784            g.setCurveWidth(v) 
     785 
     786    def setConvexCurveWidth(self, v): 
     787        self.ConvexCurveWidth = v 
     788        for g in self.graphs: 
     789            g.setConvexCurveWidth(v) 
    794790 
    795791    def setShowDiagonal(self, v): 
     
    798794            g.setShowDiagonal(v) 
    799795 
    800     def setROCconvexHullCurveWidth(self, v): 
    801         self.ROCconvexHullCurveWidth = v 
    802         for g in self.graphs: 
    803             g.setROCconvexHullCurveWidth(v) 
     796    def setConvexHullCurveWidth(self, v): 
     797        self.ConvexHullCurveWidth = v 
     798        for g in self.graphs: 
     799            g.setConvexHullCurveWidth(v) 
    804800 
    805801    def setHullColor(self, c): 
     
    813809        self.setPointWidth(self.PointWidth) 
    814810        # 
    815         self.options.lineWidthSlider.setValue(self.ROCcurveWidth) 
    816         self.options.lineWidthLCD.display(self.ROCcurveWidth) 
    817         self.setROCcurveWidth(self.ROCcurveWidth) 
     811        self.options.lineWidthSlider.setValue(self.CurveWidth) 
     812        self.options.lineWidthLCD.display(self.CurveWidth) 
     813        self.setCurveWidth(self.CurveWidth) 
    818814        # 
    819         self.options.convexWidthSlider.setValue(self.ROCconvexCurveWidth) 
    820         self.options.convexWidthLCD.display(self.ROCconvexCurveWidth) 
    821         self.setROCconvexCurveWidth(self.ROCconvexCurveWidth) 
     815        self.options.convexWidthSlider.setValue(self.ConvexCurveWidth) 
     816        self.options.convexWidthLCD.display(self.ConvexCurveWidth) 
     817        self.setConvexCurveWidth(self.ConvexCurveWidth) 
    822818        # 
    823819        self.options.showDiagonalQCB.setChecked(self.ShowDiagonal) 
    824820        self.setShowDiagonal(self.ShowDiagonal) 
    825821        # 
    826         self.options.hullWidthSlider.setValue(self.ROCconvexHullCurveWidth) 
    827         self.options.hullWidthLCD.display(self.ROCconvexHullCurveWidth) 
    828         self.setROCconvexHullCurveWidth(self.ROCconvexHullCurveWidth) 
     822        self.options.hullWidthSlider.setValue(self.ConvexHullCurveWidth) 
     823        self.options.hullWidthLCD.display(self.ConvexHullCurveWidth) 
     824        self.setConvexHullCurveWidth(self.ConvexHullCurveWidth) 
    829825        # 
    830826        self.options.hullColor.setNamedColor(QString(self.HullColor)) 
     
    864860            self.missClassificationCostQVB.hide() 
    865861 
    866         self.convexROCcurvesQCB.setEnabled(self.averagingMethod == 'merge' or self.averagingMethod == None) 
     862        self.convexCurvesQCB.setEnabled(self.averagingMethod == 'merge' or self.averagingMethod == None) 
    867863        self.missClassificationCostQVB.setEnabled(self.averagingMethod == 'merge') 
    868864        self.showPerformanceAnalysisQCB.setEnabled(self.averagingMethod == 'merge') 
     
    907903            g.setShowClassifiers(list) 
    908904 
    909     def setShowConvexROCcurves(self, v): 
    910         for g in self.graphs: 
    911             g.setShowConvexROCcurves(v) 
    912  
    913     def setShowROCconvexHull(self, v): 
    914         for g in self.graphs: 
    915             g.setShowROCconvexHull(v) 
     905    def setShowConvexCurves(self, v): 
     906        for g in self.graphs: 
     907            g.setShowConvexCurves(v) 
     908 
     909    def setShowConvexHull(self, v): 
     910        for g in self.graphs: 
     911            g.setShowConvexHull(v) 
    916912    ## 
    917913 
     
    941937            g.setNumberOfClassifiersIterationsAndClassifierColors(self.dres.classifierNames, self.numberOfIterations, self.classifierColor) 
    942938            g.setTestSetData(self.dresSplitByIterations, cl) 
    943             g.setShowConvexROCcurves(self.convexROCcurvesQCB.isChecked()) 
    944             g.setShowROCconvexHull(self.ROCconvexhullQCB.isChecked()) 
     939            g.setShowConvexCurves(self.convexCurvesQCB.isChecked()) 
     940            g.setShowConvexHull(self.convexhullQCB.isChecked()) 
    945941            g.setAveragingMethod(self.averagingMethod) 
    946942            g.setShowPerformanceLine(self.showPerformanceAnalysisQCB.isChecked()) 
     
    948944            ## user settings 
    949945            g.setPointWidth(self.PointWidth) 
    950             g.setROCcurveWidth(self.ROCcurveWidth) 
    951             g.setROCconvexCurveWidth(self.ROCconvexCurveWidth) 
     946            g.setCurveWidth(self.CurveWidth) 
     947            g.setConvexCurveWidth(self.ConvexCurveWidth) 
    952948            g.setShowDiagonal(self.ShowDiagonal) 
    953             g.setROCconvexHullCurveWidth(self.ROCconvexHullCurveWidth) 
     949            g.setConvexHullCurveWidth(self.ConvexHullCurveWidth) 
    954950            g.setHullColor(self.options.hullColor) 
    955951 
  • orange/orngStat.py

    r69 r78  
    645645 
    646646    return results 
     647 
     648 
     649## Lift Curve 
     650## returns an array of curve elements, where: 
     651##  - curve is an array of points ((TP+FP)/(P + N), TP/P, (th, FP/N)) on the Lift Curve 
     652def computeLiftCurve(res, classIndex=-1): 
     653    import corn 
     654    ## merge multiple iterations into one 
     655    mres = orngTest.ExperimentResults(1, res.classifierNames, res.classValues, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
     656    for te in res.results: 
     657        mres.results.append( te ) 
     658 
     659    problists, tots = corn.computeROCCumulative(mres, classIndex) 
     660 
     661    results = [] 
     662    P, N = tots[1], tots[0] 
     663 
     664    for plist in problists: 
     665        ## corn gives an increasing by scores list, we need a decreasing by scores 
     666        plist.reverse() 
     667        TP = 0.0 
     668        FP = 0.0 
     669        curve = [(0.0, 0.0, (10e300, 0.0))] 
     670        for (f, (thisNeg, thisPos)) in plist: 
     671            TP += thisPos 
     672            FP += thisNeg 
     673            curve.append( ((TP+FP)/(P + N), TP/P, (f, FP/N)) ) 
     674        results.append(curve) 
     675 
     676    return results 
    647677### 
    648678 
Note: See TracChangeset for help on using the changeset viewer.