Changeset 78:6d9fc54e06d8 in orange
- Timestamp:
- 04/22/03 17:16:36 (10 years ago)
- Branch:
- default
- Convert:
- fcb8fb478392a8e4488711ed65f8606c0c62fc00
- Location:
- orange
- Files:
-
- 3 added
- 3 edited
-
GUIApplications/ApplLiftCurveAnalysis.py (added)
-
OrangeWidgets/OWCalibrationPlot.py (modified) (1 diff)
-
OrangeWidgets/OWLiftCurve.py (added)
-
OrangeWidgets/OWLiftCurveOptions.py (added)
-
OrangeWidgets/OWROC.py (modified) (28 diffs)
-
orngStat.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
orange/OrangeWidgets/OWCalibrationPlot.py
r71 r78 382 382 owdm.saveSettings() 383 383 384 -
orange/OrangeWidgets/OWROC.py
r66 r78 65 65 self.splitByIterations = None 66 66 self.VTAsamples = 10 ## vertical threshold averaging, number of samples 67 self.FPcost = 500 68 self.FNcost = 500 69 self.pvalue = 400 ##0.40067 self.FPcost = 500.0 68 self.FNcost = 500.0 69 self.pvalue = 400.0 ##0.400 70 70 71 71 self.performanceLineSymbol = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.color0), QPen(self.black), QSize(7,7)) … … 73 73 74 74 self.removeCurves() 75 76 def computeCurve(self, res, classIndex=-1, keepConcavities=1): 77 return orngEval.TCcomputeROC(res, classIndex, keepConcavities) 75 78 76 79 def setNumberOfClassifiersIterationsAndClassifierColors(self, classifierNames, iterationsNum, classifierColor): … … 133 136 self.showIterations = [] 134 137 self.showConvexCurves = 0 135 self.show ROCconvexHull = 0138 self.showConvexHull = 0 136 139 self.showPerformanceLine = 0 137 140 self.showDiagonal = 0 … … 154 157 self.classifierConvexHullData = [] 155 158 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)157 159 158 160 ## diagonal curve … … 200 202 for isplit in splitByIterations: 201 203 # unmodified ROC curve 202 curves = orngEval.TCcomputeROC(isplit, self.targetClass, 1)204 curves = self.computeCurve(isplit, self.targetClass, 1) 203 205 self.setIterationCurves(iteration, curves) 204 206 205 207 # convex ROC curve 206 curves = orngEval.TCcomputeROC(isplit, self.targetClass, 0)208 curves = self.computeCurve(isplit, self.targetClass, 0) 207 209 self.setIterationConvexCurves(iteration, curves) 208 210 iteration += 1 … … 245 247 self.curve(self.classifierIterationConvexCKeys[cNum][iNum]).setEnabled(b) 246 248 247 chb = (showSomething) and (self.averagingMethod == None) and self.show ROCconvexHull249 chb = (showSomething) and (self.averagingMethod == None) and self.showConvexHull 248 250 curve = self.curve(self.classifierConvexHullCKey) 249 251 if curve <> None: curve.setEnabled(chb) 250 252 251 chb = (showSomething) and (self.averagingMethod == 'merge') and self.show ROCconvexHull253 chb = (showSomething) and (self.averagingMethod == 'merge') and self.showConvexHull 252 254 curve = self.curve(self.mergedConvexHullCKey) 253 255 if curve <> None: curve.setEnabled(chb) 254 256 255 chb = (showSomething) and (self.averagingMethod == 'vertical') and self.show ROCconvexHull257 chb = (showSomething) and (self.averagingMethod == 'vertical') and self.showConvexHull 256 258 curve = self.curve(self.verticalConvexHullCKey) 257 259 if curve <> None: curve.setEnabled(chb) 258 260 259 chb = (showSomething) and (self.averagingMethod == 'threshold') and self.show ROCconvexHull261 chb = (showSomething) and (self.averagingMethod == 'threshold') and self.showConvexHull 260 262 curve = self.curve(self.thresholdConvexHullCKey) 261 263 if curve <> None: curve.setEnabled(chb) … … 271 273 self.update() 272 274 273 def setShowConvex ROCcurves(self, b):275 def setShowConvexCurves(self, b): 274 276 self.showConvexCurves = b 275 277 self.updateCurveDisplay() 276 278 277 def setShow ROCconvexHull(self, b):278 self.show ROCconvexHull = b279 def setShowConvexHull(self, b): 280 self.showConvexHull = b 279 281 self.updateCurveDisplay() 280 282 … … 309 311 self.mergedConvexHullData = [] 310 312 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) 313 315 classifier = 0 314 316 for c in curves: … … 431 433 432 434 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] 441 437 self.setCurveData(self.mergedConvexHullCKey, x, y) 442 438 … … 469 465 ## performance line 470 466 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) 472 468 473 469 ## put the iso-performance line in point (0.0, 1.0) … … 479 475 firstp = 1 480 476 mind = 0.0 481 bestfscore = 'n/a'482 477 a = (x0*y1 - x1*y0) 483 478 closestpoints = [] 484 for (x, y, fscore ) in self.hullCurveDataForPerfLine:479 for (x, y, fscorelist) in self.hullCurveDataForPerfLine: 485 480 d = ((y0 - y1)*x + (x1 - x0)*y + a) / d01 486 481 d = abs(d) 487 482 if firstp or d < mind: 488 mind, bestfscore, firstp = d, fscore, 0489 closestpoints = [(x, y )]483 mind, firstp = d, 0 484 closestpoints = [(x, y, fscorelist)] 490 485 else: 491 486 if abs(d - mind) <= 0.0001: ## close enough 492 closestpoints.append( (x, y ) )487 closestpoints.append( (x, y, fscorelist) ) 493 488 494 489 ## now draw the closest line to the curve … … 498 493 lpy = [] 499 494 first = 1 500 for (x, y ) in closestpoints:495 for (x, y, fscorelist) in closestpoints: 501 496 if first: 502 497 first = 0 … … 507 502 px = x 508 503 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]) 510 506 py = py - 0.05 511 507 mkey = self.insertMarker(s) … … 523 519 524 520 def costChanged(self, FPcost, FNcost): 525 self.FPcost = FPcost526 self.FNcost = FNcost521 self.FPcost = float(FPcost) 522 self.FNcost = float(FNcost) 527 523 self.calcUpdatePerformanceLine() 528 524 529 525 def pChanged(self, pvalue): 530 self.pvalue = pvalue526 self.pvalue = float(pvalue) 531 527 self.calcUpdatePerformanceLine() 532 528 … … 536 532 self.update() 537 533 538 def set ROCcurveWidth(self, v):534 def setCurveWidth(self, v): 539 535 for cNum in range(len(self.showClassifiers)): 540 536 self.setCurvePen(self.mergedCKeys[cNum], QPen(self.classifierColor[cNum], v)) … … 545 541 self.update() 546 542 547 def set ROCconvexCurveWidth(self, v):543 def setConvexCurveWidth(self, v): 548 544 for cNum in range(len(self.showClassifiers)): 549 545 self.setCurvePen(self.mergedConvexCKeys[cNum], QPen(self.classifierColor[cNum], v)) … … 556 552 self.updateCurveDisplay() 557 553 558 def set ROCconvexHullCurveWidth(self, v):554 def setConvexHullCurveWidth(self, v): 559 555 self.convexHullPen.setWidth(v) 560 556 self.setCurvePen(self.mergedConvexHullCKey, self.convexHullPen) … … 637 633 638 634 class OWROC(OWWidget): 639 settingsList = ["PointWidth", " ROCcurveWidth", "ROCconvexCurveWidth", "ShowDiagonal",640 " ROCconvexHullCurveWidth", "HullColor"]635 settingsList = ["PointWidth", "CurveWidth", "ConvexCurveWidth", "ShowDiagonal", 636 "ConvexHullCurveWidth", "HullColor"] 641 637 def __init__(self,parent=None): 642 638 "Constructor" … … 651 647 #set default settings 652 648 self.PointWidth = 7 653 self. ROCcurveWidth = 3654 self. ROCconvexCurveWidth = 1649 self.CurveWidth = 3 650 self.ConvexCurveWidth = 1 655 651 self.ShowDiagonal = TRUE 656 self. ROCconvexHullCurveWidth = 3652 self.ConvexHullCurveWidth = 3 657 653 self.HullColor = str(Qt.yellow.name()) 658 654 … … 695 691 #connect GUI controls of options in options dialog to settings 696 692 self.connect(self.options.pointWidthSlider, SIGNAL("valueChanged(int)"), self.setPointWidth) 697 self.connect(self.options.lineWidthSlider, SIGNAL("valueChanged(int)"), self.set ROCcurveWidth)698 self.connect(self.options.convexWidthSlider, SIGNAL("valueChanged(int)"), self.set ROCconvexCurveWidth)693 self.connect(self.options.lineWidthSlider, SIGNAL("valueChanged(int)"), self.setCurveWidth) 694 self.connect(self.options.convexWidthSlider, SIGNAL("valueChanged(int)"), self.setConvexCurveWidth) 699 695 self.connect(self.options.showDiagonalQCB, SIGNAL("toggled(bool)"), self.setShowDiagonal) 700 self.connect(self.options.hullWidthSlider, SIGNAL("valueChanged(int)"), self.set ROCconvexHullCurveWidth)696 self.connect(self.options.hullWidthSlider, SIGNAL("valueChanged(int)"), self.setConvexHullCurveWidth) 701 697 self.connect(self.options, PYSIGNAL("hullColorChange(QColor &)"), self.setHullColor) 702 698 … … 724 720 725 721 # show convex ROC curves 726 self.convex ROCcurvesQCB = QCheckBox("convex ROC curves", self.classifiersQVGB) ## !!! only in None and Merge average mode727 self.connect(self.convex ROCcurvesQCB, 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) 728 724 729 725 # 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) 732 728 733 729 ## test set selection (testSetsQLB) … … 783 779 g.setPointWidth(v) 784 780 785 def set ROCcurveWidth(self, v):786 self. ROCcurveWidth = v787 for g in self.graphs: 788 g.set ROCcurveWidth(v)789 790 def set ROCconvexCurveWidth(self, v):791 self. ROCconvexCurveWidth = v792 for g in self.graphs: 793 g.set ROCconvexCurveWidth(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) 794 790 795 791 def setShowDiagonal(self, v): … … 798 794 g.setShowDiagonal(v) 799 795 800 def set ROCconvexHullCurveWidth(self, v):801 self. ROCconvexHullCurveWidth = v802 for g in self.graphs: 803 g.set ROCconvexHullCurveWidth(v)796 def setConvexHullCurveWidth(self, v): 797 self.ConvexHullCurveWidth = v 798 for g in self.graphs: 799 g.setConvexHullCurveWidth(v) 804 800 805 801 def setHullColor(self, c): … … 813 809 self.setPointWidth(self.PointWidth) 814 810 # 815 self.options.lineWidthSlider.setValue(self. ROCcurveWidth)816 self.options.lineWidthLCD.display(self. ROCcurveWidth)817 self.set ROCcurveWidth(self.ROCcurveWidth)811 self.options.lineWidthSlider.setValue(self.CurveWidth) 812 self.options.lineWidthLCD.display(self.CurveWidth) 813 self.setCurveWidth(self.CurveWidth) 818 814 # 819 self.options.convexWidthSlider.setValue(self. ROCconvexCurveWidth)820 self.options.convexWidthLCD.display(self. ROCconvexCurveWidth)821 self.set ROCconvexCurveWidth(self.ROCconvexCurveWidth)815 self.options.convexWidthSlider.setValue(self.ConvexCurveWidth) 816 self.options.convexWidthLCD.display(self.ConvexCurveWidth) 817 self.setConvexCurveWidth(self.ConvexCurveWidth) 822 818 # 823 819 self.options.showDiagonalQCB.setChecked(self.ShowDiagonal) 824 820 self.setShowDiagonal(self.ShowDiagonal) 825 821 # 826 self.options.hullWidthSlider.setValue(self. ROCconvexHullCurveWidth)827 self.options.hullWidthLCD.display(self. ROCconvexHullCurveWidth)828 self.set ROCconvexHullCurveWidth(self.ROCconvexHullCurveWidth)822 self.options.hullWidthSlider.setValue(self.ConvexHullCurveWidth) 823 self.options.hullWidthLCD.display(self.ConvexHullCurveWidth) 824 self.setConvexHullCurveWidth(self.ConvexHullCurveWidth) 829 825 # 830 826 self.options.hullColor.setNamedColor(QString(self.HullColor)) … … 864 860 self.missClassificationCostQVB.hide() 865 861 866 self.convex ROCcurvesQCB.setEnabled(self.averagingMethod == 'merge' or self.averagingMethod == None)862 self.convexCurvesQCB.setEnabled(self.averagingMethod == 'merge' or self.averagingMethod == None) 867 863 self.missClassificationCostQVB.setEnabled(self.averagingMethod == 'merge') 868 864 self.showPerformanceAnalysisQCB.setEnabled(self.averagingMethod == 'merge') … … 907 903 g.setShowClassifiers(list) 908 904 909 def setShowConvex ROCcurves(self, v):910 for g in self.graphs: 911 g.setShowConvex ROCcurves(v)912 913 def setShow ROCconvexHull(self, v):914 for g in self.graphs: 915 g.setShow ROCconvexHull(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) 916 912 ## 917 913 … … 941 937 g.setNumberOfClassifiersIterationsAndClassifierColors(self.dres.classifierNames, self.numberOfIterations, self.classifierColor) 942 938 g.setTestSetData(self.dresSplitByIterations, cl) 943 g.setShowConvex ROCcurves(self.convexROCcurvesQCB.isChecked())944 g.setShow ROCconvexHull(self.ROCconvexhullQCB.isChecked())939 g.setShowConvexCurves(self.convexCurvesQCB.isChecked()) 940 g.setShowConvexHull(self.convexhullQCB.isChecked()) 945 941 g.setAveragingMethod(self.averagingMethod) 946 942 g.setShowPerformanceLine(self.showPerformanceAnalysisQCB.isChecked()) … … 948 944 ## user settings 949 945 g.setPointWidth(self.PointWidth) 950 g.set ROCcurveWidth(self.ROCcurveWidth)951 g.set ROCconvexCurveWidth(self.ROCconvexCurveWidth)946 g.setCurveWidth(self.CurveWidth) 947 g.setConvexCurveWidth(self.ConvexCurveWidth) 952 948 g.setShowDiagonal(self.ShowDiagonal) 953 g.set ROCconvexHullCurveWidth(self.ROCconvexHullCurveWidth)949 g.setConvexHullCurveWidth(self.ConvexHullCurveWidth) 954 950 g.setHullColor(self.options.hullColor) 955 951 -
orange/orngStat.py
r69 r78 645 645 646 646 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 652 def 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 647 677 ### 648 678
Note: See TracChangeset
for help on using the changeset viewer.
