Changeset 10190:c96ebb996a6f in orange
 Timestamp:
 02/13/12 12:49:02 (2 years ago)
 Branch:
 default
 rebase_source:
 f2b6f090b9a5a092c4d193ff305d55805c8848fa
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/evaluation/scoring.py
r10177 r10190 45 45 res.weights, classifiers=res.classifiers, 46 46 loaded=res.loaded, test_type=res.test_type, labels=res.labels) 47 for iin range(res.number_of_iterations)]47 for _ in range(res.number_of_iterations)] 48 48 for te in res.results: 49 49 ress[te.iteration_number].results.append(te) … … 188 188 if argkw.get("SE", 0) and res.number_of_iterations > 1: 189 189 # computes the scores for each iteration, then averages 190 scores = [[0.0] * res.number_of_iterations for iin range(res.number_of_learners)]190 scores = [[0.0] * res.number_of_iterations for _ in range(res.number_of_learners)] 191 191 if argkw.get("normabs", 0) or argkw.get("normsqr", 0): 192 192 norm = [0.0] * res.number_of_iterations … … 400 400 401 401 def from_confusion_matrix_list(self, confusion_matrices, report_se): 402 return map(self.from_confusion_matrix, confusion_matrices) # TODO: report_se 402 return [self.from_confusion_matrix(cm, report_se=report_se) 403 for cm in confusion_matrices] 403 404 404 405 def from_classification_results(self, test_results, report_se, ignore_results): … … 418 419 419 420 def from_crossvalidation_results(self, test_results, report_se, ignore_weights): 420 CAsByFold = [[0.0]*test_results.number_of_iterations for iin range(test_results.number_of_learners)]421 CAsByFold = [[0.0]*test_results.number_of_iterations for _ in range(test_results.number_of_learners)] 421 422 foldN = [0.0]*test_results.number_of_iterations 422 423 … … 461 462 return [AP/totweight for AP in APs] 462 463 463 APsByFold = [[0.0]*res.number_of_learners for iin range(res.number_of_iterations)]464 APsByFold = [[0.0]*res.number_of_learners for _ in range(res.number_of_iterations)] 464 465 foldN = [0.0] * res.number_of_iterations 465 466 if ignore_weights or not res.weights: … … 536 537 537 538 def IS_ex(Pc, P): 538 " Pc aposterior probability, P aprior"539 if (Pc>=P):539 """Pc aposterior probability, P aprior""" 540 if Pc>=P: 540 541 return log2(P)+log2(Pc) 541 542 else: … … 575 576 576 577 577 ISs = [[0.0]*res.number_of_iterations for iin range(res.number_of_learners)]578 ISs = [[0.0]*res.number_of_iterations for _ in range(res.number_of_learners)] 578 579 foldN = [0.] * res.number_of_iterations 579 580 … … 600 601 ranks = statc.rankdata(apply(statistics, (ri,), argkw)) 601 602 if sums: 602 sums = sums and [ranks[i]+sums[i] for i in range(k)] 603 sums = sums and [ranks[i]+sums[i] for i in range(k)] # TODO: What is k? 603 604 else: 604 605 sums = ranks … … 614 615 res1, res2 = [], [] 615 616 for ri in split_by_iterations(res): 616 stats = apply(statistics, (ri,),argkw)617 if (len(stats) != 2):617 stats = statistics(ri, **argkw) 618 if len(stats) != 2: 618 619 raise TypeError, "Wilcoxon compares two classifiers, no more, no less" 619 620 res1.append(stats[0]) … … 664 665 cm[li][trueClass][predClass] += 1 665 666 else: 666 for tex in enumerate(test_results.results):667 for tex in test_results.results: 667 668 trueClass = int(tex.actual_class) 668 669 for li, pred in tex.classes: … … 1012 1013 ## T Fawcett: ROC Graphs: Notes and Practical Considerations for Data Mining Researchers, submitted to KDD Journal. 1013 1014 def ROC_slope((P1x, P1y, P1fscore), (P2x, P2y, P2fscore)): 1014 if (P1x == P2x):1015 if P1x == P2x: 1015 1016 return 1e300 1016 1017 return (P1y  P2y) / (P1x  P2x) … … 1623 1624 iterations, all_ite = [res], None 1624 1625 1625 aucs = [[[] for i in range(numberOfClasses)] for iin range(number_of_learners)]1626 aucs = [[[] for _ in range(numberOfClasses)] for _ in range(number_of_learners)] 1626 1627 prob = class_probabilities_from_res(res) 1627 1628 … … 1785 1786 file.write("set xrange [%f:%f]\n" % (proportions[0], proportions[1])) 1786 1787 file.write("set multiplot\n\n") 1787 CAs = [CA _dev(x) for x in all_results]1788 CAs = [CA(x, report_se=True) for x in all_results] 1788 1789 1789 1790 file.write("plot \\\n") … … 1813 1814 import types 1814 1815 fopened=0 1815 if (type(file)==types.StringType):1816 if type(file)==types.StringType: 1816 1817 file=open(file, "wt") 1817 1818 fopened=1 … … 1830 1831 import types 1831 1832 fopened=0 1832 if (type(file)==types.StringType):1833 if type(file)==types.StringType: 1833 1834 file=open(file, "wt") 1834 1835 fopened=1 … … 1866 1867 import types 1867 1868 fopened=0 1868 if (type(file)==types.StringType):1869 if type(file)==types.StringType: 1869 1870 file=open(file, "wt") 1870 1871 fopened=1 … … 1900 1901 import types 1901 1902 fopened=0 1902 if (type(file)==types.StringType):1903 if type(file)==types.StringType: 1903 1904 file=open(file, "wt") 1904 1905 fopened=1 1905 1906 1906 1907 nexamples=len(all_results[0].results) 1907 CAs = [CA _dev(x) for x in all_results]1908 CAs = [CA(x, report_se=True) for x in all_results] 1908 1909 1909 1910 graphsize=float(options.get("graphsize", 10.0)) #cm … … 1980 1981 import types 1981 1982 fopened=0 1982 if (type(file)==types.StringType):1983 if type(file)==types.StringType: 1983 1984 file=open(file, "wt") 1984 1985 fopened=1 … … 2130 2131 from matplotlib.patches import Polygon 2131 2132 from matplotlib.backends.backend_agg import FigureCanvasAgg 2132 except :2133 except ImportError: 2133 2134 import sys 2134 2135 print >> sys.stderr, "Function requires matplotlib. Please install it." … … 2146 2147 nnames = [ names[x] for x in sortidx ] 2147 2148 2148 if lowv ==None:2149 if lowv is None: 2149 2150 lowv = min(1, int(math.floor(min(ssums)))) 2150 if highv ==None:2151 if highv is None: 2151 2152 highv = max(len(avranks), int(math.ceil(max(ssums)))) 2152 2153 … … 2170 2171 distanceh = 0.25 2171 2172 2172 if cd and cdmethod ==None:2173 if cd and cdmethod is None: 2173 2174 2174 2175 #get pairs of non significant methods … … 2217 2218 return [ a*wf for a in l ] 2218 2219 2219 """ 2220 Upper left corner is (0,0). 2221 """ 2220 2221 # Upper left corner is (0,0). 2222 2222 2223 2223 ax.plot([0,1], [0,1], c="w") … … 2262 2262 text(textspace+scalewidth+0.2, chei, nnames[i], ha="left", va="center") 2263 2263 2264 if cd and cdmethod ==None:2264 if cd and cdmethod is None: 2265 2265 2266 2266 #upper scale … … 2341 2341 for real, pred in zip(labels, aclass): 2342 2342 if real and pred: 2343 intersection = intersection+12343 intersection += 1 2344 2344 if real or pred: 2345 union = union+12346 2347 if union != 0:2348 accuracies[i] = accuracies[i] + intersection/union2345 union += 1 2346 2347 if union: 2348 accuracies[i] += intersection / union 2349 2349 2350 2350 return [math.pow(x/example_num,forgiveness_rate) for x in accuracies] … … 2369 2369 for real, pred in zip(labels, aclass): 2370 2370 if real and pred: 2371 intersection = intersection+12371 intersection += 1 2372 2372 if real: 2373 predicted = predicted +12374 if predicted <> 0:2375 precisions[i] = precisions[i] + intersection/predicted2373 predicted += 1 2374 if predicted: 2375 precisions[i] += intersection / predicted 2376 2376 2377 2377 return [x/example_num for x in precisions] … … 2396 2396 for real, pred in zip(labels, aclass): 2397 2397 if real and pred: 2398 intersection = intersection+12398 intersection += 1 2399 2399 if pred: 2400 actual = actual +12401 if actual <> 0:2402 recalls[i] = recalls[i] + intersection/actual2400 actual += 1 2401 if actual: 2402 recalls[i] += intersection / actual 2403 2403 2404 2404 return [x/example_num for x in recalls]
Note: See TracChangeset
for help on using the changeset viewer.