Changeset 10195:a21839c2726e in orange
 Timestamp:
 02/13/12 16:04:49 (2 years ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/evaluation/scoring.py
r10190 r10195 7 7 from Orange.misc import deprecated_keywords, deprecated_function_name, deprecation_warning 8 8 from Orange.evaluation import testing 9 10 try: 11 import matplotlib 12 HAS_MATPLOTLIB = True 13 except ImportError: 14 HAS_MATPLOTLIB = False 9 15 10 16 #### Private stuff … … 189 195 # computes the scores for each iteration, then averages 190 196 scores = [[0.0] * res.number_of_iterations for _ in range(res.number_of_learners)] 197 norm=None 191 198 if argkw.get("normabs", 0) or argkw.get("normsqr", 0): 192 199 norm = [0.0] * res.number_of_iterations … … 255 262 else: 256 263 # UNFINISHED 264 MSEs = [0.]*res.number_of_learners 257 265 for tex in res.results: 258 266 MSEs = map(lambda res, cls, ac = float(tex.actual_class), … … 314 322 """MSE(res) > meansquared error""" 315 323 if argkw.get("SE", 0) and res.number_of_iterations > 1: 316 MSEs = [[0.0] * res.number_of_iterations for iin range(res.number_of_learners)]324 MSEs = [[0.0] * res.number_of_iterations for _ in range(res.number_of_learners)] 317 325 nIter = [0]*res.number_of_iterations 318 326 if argkw.get("unweighted", 0) or not res.weights: … … 513 521 return [max(x/totweight+1.0, 0) for x in MSEs] 514 522 515 BSs = [[0.0]*res.number_of_learners for iin range(res.number_of_iterations)]523 BSs = [[0.0]*res.number_of_learners for _ in range(res.number_of_iterations)] 516 524 foldN = [0.] * res.number_of_iterations 517 525 … … 627 635 628 636 k = len(res.results[0].classes) 629 if (k<2):637 if k<2: 630 638 raise TypeError, "nothing to compare (less than two classifiers given)" 631 639 if k==2: … … 656 664 numberOfClasses = len(test_results.class_values) 657 665 if class_index < 1 or numberOfClasses > 2: 658 cm = [[[0.0] * numberOfClasses for i in range(numberOfClasses)] for lin range(test_results.number_of_learners)]666 cm = [[[0.0] * numberOfClasses for _ in range(numberOfClasses)] for _ in range(test_results.number_of_learners)] 659 667 if ignore_weights or not test_results.weights: 660 668 for tex in test_results.results: … … 920 928 marginalSumOfColumns = numpy.sum(confusion_matrix, axis=1) 921 929 jointProportion = (marginalSumOfColumns + marginalSumOfRows)/ \ 922 (2.0 * numpy.sum(confusion_matrix , axis=None))930 (2.0 * numpy.sum(confusion_matrix)) 923 931 # In the eq. above, 2.0 is what the Wikipedia page calls 924 932 # the number of annotators. Here we have two annotators: … … 926 934 # the learners. 927 935 928 prExpected = numpy.sum(jointProportion ** 2 , axis=None)929 prActual = numpy.sum(numpy.diag(confusion_matrix) , axis=None)/numpy.sum(confusion_matrix, axis=None)936 prExpected = numpy.sum(jointProportion ** 2) 937 prActual = numpy.sum(numpy.diag(confusion_matrix)) /numpy.sum(confusion_matrix) 930 938 931 939 ret = (prActual  prExpected) / (1.0  prExpected) … … 1023 1031 R.append(P) 1024 1032 else: 1025 while (1):1033 while True: 1026 1034 if len(R) < 2: 1027 1035 R.append(P) … … 1110 1118 "A range function, that does accept float increments..." 1111 1119 1112 if end ==None:1120 if end is None: 1113 1121 end = start + 0.0 1114 1122 start = 0.0 1115 1123 1116 if inc ==None or inc == 0:1124 if inc is None or inc == 0: 1117 1125 inc = 1.0 1118 1126 … … 1150 1158 while i < npts  1: 1151 1159 (fp, _, _) = ROC[i + 1] 1152 if (fp <= FPsample):1160 if fp <= FPsample: 1153 1161 i += 1 1154 1162 else: … … 1188 1196 stdev.append(TPstd) 1189 1197 1190 return (average, stdev)1198 return average, stdev 1191 1199 1192 1200 ## input ROCcurves are of form [ROCcurves1, ROCcurves2, ... ROCcurvesN], … … 1202 1210 while i < npts  1: 1203 1211 (px, py, pfscore) = ROC[i] 1204 if (pfscore > thresh):1212 if pfscore > thresh: 1205 1213 i += 1 1206 1214 else: … … 1315 1323 else: 1316 1324 curve = loessCurve 1317 curve = [ (c)[:2] for c in curve] ## remove the third value (variance of epsilon?) that suddenly appeared in the output of the statc.loess function1325 curve = [c[:2] for c in curve] ## remove the third value (variance of epsilon?) that suddenly appeared in the output of the statc.loess function 1318 1326 results.append((curve, yesClassRugPoints, noClassRugPoints)) 1319 1327 … … 1372 1380 weightByClasses = argkw.get("weightByClasses", True) 1373 1381 1374 if (res.number_of_iterations>1):1382 if res.number_of_iterations>1: 1375 1383 CDTs = [CDT() for i in range(res.number_of_learners)] 1376 1384 iterationExperiments = split_by_iterations(res) … … 1451 1459 res.number_of_iterations)) 1452 1460 if subsum_aucs: 1453 if method == 0:1461 if method == self.ByWeightedPairs: 1454 1462 p_ij = prob[classIndex1] * prob[classIndex2] 1455 1463 subsum_aucs = [x * p_ij for x in subsum_aucs] … … 1465 1473 res.number_of_iterations)) 1466 1474 if subsum_aucs: 1467 if method == 0:1475 if method == self.ByWeightedPairs: 1468 1476 p_i = prob[classIndex] 1469 1477 subsum_aucs = [x * p_i for x in subsum_aucs] … … 2038 2046 k = len(avranks) 2039 2047 2040 d = {} 2048 d = {("nemenyi", "0.05"): [0, 0, 1.959964, 2.343701, 2.569032, 2.727774, 2049 2.849705, 2.94832, 3.030879, 3.101730, 3.163684, 2050 3.218654, 3.268004, 3.312739, 3.353618, 3.39123, 2051 3.426041, 3.458425, 3.488685, 3.517073, 3.543799] 2052 , ("nemenyi", "0.1"): [0, 0, 1.644854, 2.052293, 2.291341, 2.459516, 2053 2.588521, 2.692732, 2.779884, 2.854606, 2.919889, 2054 2.977768, 3.029694, 3.076733, 3.119693, 3.159199, 2055 3.195743, 3.229723, 3.261461, 3.291224, 3.319233] 2056 , ("bonferronidunn", "0.05"): [0, 0, 1.960, 2.241, 2.394, 2.498, 2.576, 2057 2.638, 2.690, 2.724, 2.773], 2058 ("bonferronidunn", "0.1"): [0, 0, 1.645, 1.960, 2.128, 2.241, 2.326, 2059 2.394, 2.450, 2.498, 2.539]} 2041 2060 2042 2061 #can be computed in R as qtukey(0.95, n, Inf)**0.5 2043 2062 #for (x in c(2:20)) print(qtukey(0.95, x, Inf)/(2**0.5) 2044 d[("nemenyi", "0.05")] = [0, 0, 1.959964, 2.343701, 2.569032, 2.727774, 2.849705, 2.94832, 3.030879, 3.101730, 3.163684, 3.218654, 3.268004, 3.312739, 3.353618, 3.39123, 3.426041, 3.458425, 3.488685, 3.517073, 3.543799 ]2045 d[("nemenyi", "0.1")] = [0, 0, 1.644854, 2.052293, 2.291341, 2.459516, 2.588521, 2.692732, 2.779884, 2.854606, 2.919889, 2.977768, 3.029694, 3.076733, 3.119693, 3.159199, 3.195743, 3.229723, 3.261461, 3.291224, 3.319233 ]2046 2047 d[("bonferronidunn", "0.05")] = [0, 0, 1.960, 2.241, 2.394, 2.498, 2.576, 2.638, 2.690, 2.724, 2.773 ]2048 d[("bonferronidunn", "0.1")] = [0, 0, 1.645, 1.960, 2.128, 2.241, 2.326, 2.394, 2.450, 2.498, 2.539 ]2049 2063 2050 2064 q = d[(type, alpha)] … … 2076 2090 :param textspace: Space on figure sides left for the description 2077 2091 of methods, default 1 in. 2078 :param reverse: If True, the lowest rank is on the right. Default : False.2092 :param reverse: If True, the lowest rank is on the right. Default\: False. 2079 2093 :param cdmethod: None by default. It can be an index of element in avranks 2080 2094 or or names which specifies the method which should be 2081 2095 marked with an interval. 2082 2096 """ 2097 if not HAS_MATPLOTLIB: 2098 import sys 2099 print >> sys.stderr, "Function requires matplotlib. Please install it." 2100 return 2083 2101 2084 2102 width = float(width) … … 2116 2134 2117 2135 """ 2118 if len(lr) == 0:2136 if not len(lr): 2119 2137 yield () 2120 2138 else: … … 2127 2145 yield tuple([a] + list(b)) 2128 2146 2129 try: 2130 from matplotlib.figure import Figure 2131 from matplotlib.patches import Polygon 2132 from matplotlib.backends.backend_agg import FigureCanvasAgg 2133 except ImportError: 2134 import sys 2135 print >> sys.stderr, "Function requires matplotlib. Please install it." 2136 return 2147 2148 from matplotlib.figure import Figure 2149 from matplotlib.backends.backend_agg import FigureCanvasAgg 2137 2150 2138 2151 def print_figure(fig, *args, **kwargs): … … 2253 2266 2254 2267 for i in range((k+1)/2): 2255 chei = cline+ minnotsignificant + (i)*0.22268 chei = cline+ minnotsignificant + i *0.2 2256 2269 line([(rankpos(ssums[i]), cline), (rankpos(ssums[i]), chei), (textspace0.1, chei)], linewidth=0.7) 2257 2270 text(textspace0.2, chei, nnames[i], ha="right", va="center")
Note: See TracChangeset
for help on using the changeset viewer.