Changeset 10190:c96ebb996a6f in orange


Ignore:
Timestamp:
02/13/12 12:49:02 (2 years ago)
Author:
anze <anze.staric@…>
Branch:
default
rebase_source:
f2b6f090b9a5a092c4d193ff305d55805c8848fa
Message:

Fixed some warnings in evaluation.scoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/evaluation/scoring.py

    r10177 r10190  
    4545                res.weights, classifiers=res.classifiers, 
    4646                loaded=res.loaded, test_type=res.test_type, labels=res.labels) 
    47             for i in range(res.number_of_iterations)] 
     47            for _ in range(res.number_of_iterations)] 
    4848    for te in res.results: 
    4949        ress[te.iteration_number].results.append(te) 
     
    188188    if argkw.get("SE", 0) and res.number_of_iterations > 1: 
    189189        # computes the scores for each iteration, then averages 
    190         scores = [[0.0] * res.number_of_iterations for i in range(res.number_of_learners)] 
     190        scores = [[0.0] * res.number_of_iterations for _ in range(res.number_of_learners)] 
    191191        if argkw.get("norm-abs", 0) or argkw.get("norm-sqr", 0): 
    192192            norm = [0.0] * res.number_of_iterations 
     
    400400 
    401401    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] 
    403404 
    404405    def from_classification_results(self, test_results, report_se, ignore_results): 
     
    418419 
    419420    def from_crossvalidation_results(self, test_results, report_se, ignore_weights): 
    420         CAsByFold = [[0.0]*test_results.number_of_iterations for i in range(test_results.number_of_learners)] 
     421        CAsByFold = [[0.0]*test_results.number_of_iterations for _ in range(test_results.number_of_learners)] 
    421422        foldN = [0.0]*test_results.number_of_iterations 
    422423 
     
    461462        return [AP/totweight for AP in APs] 
    462463 
    463     APsByFold = [[0.0]*res.number_of_learners for i in range(res.number_of_iterations)] 
     464    APsByFold = [[0.0]*res.number_of_learners for _ in range(res.number_of_iterations)] 
    464465    foldN = [0.0] * res.number_of_iterations 
    465466    if ignore_weights or not res.weights: 
     
    536537 
    537538def IS_ex(Pc, P): 
    538     "Pc aposterior probability, P aprior" 
    539     if (Pc>=P): 
     539    """Pc aposterior probability, P aprior""" 
     540    if Pc>=P: 
    540541        return -log2(P)+log2(Pc) 
    541542    else: 
     
    575576 
    576577         
    577     ISs = [[0.0]*res.number_of_iterations for i in range(res.number_of_learners)] 
     578    ISs = [[0.0]*res.number_of_iterations for _ in range(res.number_of_learners)] 
    578579    foldN = [0.] * res.number_of_iterations 
    579580 
     
    600601        ranks = statc.rankdata(apply(statistics, (ri,), argkw)) 
    601602        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? 
    603604        else: 
    604605            sums = ranks 
     
    614615    res1, res2 = [], [] 
    615616    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: 
    618619            raise TypeError, "Wilcoxon compares two classifiers, no more, no less" 
    619620        res1.append(stats[0]) 
     
    664665                            cm[li][trueClass][predClass] += 1 
    665666            else: 
    666                 for tex in enumerate(test_results.results): 
     667                for tex in test_results.results: 
    667668                    trueClass = int(tex.actual_class) 
    668669                    for li, pred in tex.classes: 
     
    10121013## T Fawcett: ROC Graphs: Notes and Practical Considerations for Data Mining Researchers, submitted to KDD Journal.  
    10131014def ROC_slope((P1x, P1y, P1fscore), (P2x, P2y, P2fscore)): 
    1014     if (P1x == P2x): 
     1015    if P1x == P2x: 
    10151016        return 1e300 
    10161017    return (P1y - P2y) / (P1x - P2x) 
     
    16231624        iterations, all_ite = [res], None 
    16241625     
    1625     aucs = [[[] for i in range(numberOfClasses)] for i in range(number_of_learners)] 
     1626    aucs = [[[] for _ in range(numberOfClasses)] for _ in range(number_of_learners)] 
    16261627    prob = class_probabilities_from_res(res) 
    16271628         
     
    17851786    file.write("set xrange [%f:%f]\n" % (proportions[0], proportions[-1])) 
    17861787    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] 
    17881789 
    17891790    file.write("plot \\\n") 
     
    18131814    import types 
    18141815    fopened=0 
    1815     if (type(file)==types.StringType): 
     1816    if type(file)==types.StringType: 
    18161817        file=open(file, "wt") 
    18171818        fopened=1 
     
    18301831    import types 
    18311832    fopened=0 
    1832     if (type(file)==types.StringType): 
     1833    if type(file)==types.StringType: 
    18331834        file=open(file, "wt") 
    18341835        fopened=1 
     
    18661867    import types 
    18671868    fopened=0 
    1868     if (type(file)==types.StringType): 
     1869    if type(file)==types.StringType: 
    18691870        file=open(file, "wt") 
    18701871        fopened=1 
     
    19001901    import types 
    19011902    fopened=0 
    1902     if (type(file)==types.StringType): 
     1903    if type(file)==types.StringType: 
    19031904        file=open(file, "wt") 
    19041905        fopened=1 
    19051906 
    19061907    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] 
    19081909 
    19091910    graphsize=float(options.get("graphsize", 10.0)) #cm 
     
    19801981    import types 
    19811982    fopened=0 
    1982     if (type(file)==types.StringType): 
     1983    if type(file)==types.StringType: 
    19831984        file=open(file, "wt") 
    19841985        fopened=1 
     
    21302131        from matplotlib.patches import Polygon 
    21312132        from matplotlib.backends.backend_agg import FigureCanvasAgg 
    2132     except: 
     2133    except ImportError: 
    21332134        import sys 
    21342135        print >> sys.stderr, "Function requires matplotlib. Please install it." 
     
    21462147    nnames = [ names[x] for x in sortidx ] 
    21472148     
    2148     if lowv == None: 
     2149    if lowv is None: 
    21492150        lowv = min(1, int(math.floor(min(ssums)))) 
    2150     if highv == None: 
     2151    if highv is None: 
    21512152        highv = max(len(avranks), int(math.ceil(max(ssums)))) 
    21522153 
     
    21702171    distanceh = 0.25 
    21712172 
    2172     if cd and cdmethod == None: 
     2173    if cd and cdmethod is None: 
    21732174     
    21742175        #get pairs of non significant methods 
     
    22172218        return [ a*wf for a in l ] 
    22182219 
    2219     """ 
    2220     Upper left corner is (0,0). 
    2221     """ 
     2220 
     2221    # Upper left corner is (0,0). 
    22222222 
    22232223    ax.plot([0,1], [0,1], c="w") 
     
    22622262        text(textspace+scalewidth+0.2, chei, nnames[i], ha="left", va="center") 
    22632263 
    2264     if cd and cdmethod == None: 
     2264    if cd and cdmethod is None: 
    22652265 
    22662266        #upper scale 
     
    23412341            for real, pred in zip(labels, aclass): 
    23422342                if real and pred: 
    2343                     intersection = intersection+1 
     2343                    intersection += 1 
    23442344                if real or pred: 
    2345                     union = union+1 
    2346  
    2347             if union != 0: 
    2348                 accuracies[i] = accuracies[i] + intersection/union 
     2345                    union += 1 
     2346 
     2347            if union: 
     2348                accuracies[i] += intersection / union 
    23492349             
    23502350    return [math.pow(x/example_num,forgiveness_rate) for x in accuracies] 
     
    23692369            for real, pred in zip(labels, aclass): 
    23702370                if real and pred: 
    2371                     intersection = intersection+1 
     2371                    intersection += 1 
    23722372                if real: 
    2373                     predicted = predicted + 1 
    2374             if predicted <> 0: 
    2375                 precisions[i] = precisions[i] + intersection/predicted 
     2373                    predicted += 1 
     2374            if predicted: 
     2375                precisions[i] += intersection / predicted 
    23762376             
    23772377    return [x/example_num for x in precisions] 
     
    23962396            for real, pred in zip(labels, aclass): 
    23972397                if real and pred: 
    2398                     intersection = intersection+1 
     2398                    intersection += 1 
    23992399                if pred: 
    2400                     actual = actual + 1 
    2401             if actual <> 0: 
    2402                 recalls[i] = recalls[i] + intersection/actual 
     2400                    actual += 1 
     2401            if actual: 
     2402                recalls[i] += intersection / actual 
    24032403             
    24042404    return [x/example_num for x in recalls] 
Note: See TracChangeset for help on using the changeset viewer.