Changeset 10195:a21839c2726e in orange


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

Fixed a bunch of warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/evaluation/scoring.py

    r10190 r10195  
    77from Orange.misc import deprecated_keywords, deprecated_function_name, deprecation_warning 
    88from Orange.evaluation import testing 
     9 
     10try: 
     11    import matplotlib 
     12    HAS_MATPLOTLIB = True 
     13except ImportError: 
     14    HAS_MATPLOTLIB = False 
    915 
    1016#### Private stuff 
     
    189195        # computes the scores for each iteration, then averages 
    190196        scores = [[0.0] * res.number_of_iterations for _ in range(res.number_of_learners)] 
     197        norm=None 
    191198        if argkw.get("norm-abs", 0) or argkw.get("norm-sqr", 0): 
    192199            norm = [0.0] * res.number_of_iterations 
     
    255262        else: 
    256263            # UNFINISHED 
     264            MSEs = [0.]*res.number_of_learners 
    257265            for tex in res.results: 
    258266                MSEs = map(lambda res, cls, ac = float(tex.actual_class), 
     
    314322    """MSE(res) -> mean-squared error""" 
    315323    if argkw.get("SE", 0) and res.number_of_iterations > 1: 
    316         MSEs = [[0.0] * res.number_of_iterations for i in range(res.number_of_learners)] 
     324        MSEs = [[0.0] * res.number_of_iterations for _ in range(res.number_of_learners)] 
    317325        nIter = [0]*res.number_of_iterations 
    318326        if argkw.get("unweighted", 0) or not res.weights: 
     
    513521            return [max(x/totweight+1.0, 0) for x in MSEs] 
    514522 
    515     BSs = [[0.0]*res.number_of_learners for i in range(res.number_of_iterations)] 
     523    BSs = [[0.0]*res.number_of_learners for _ in range(res.number_of_iterations)] 
    516524    foldN = [0.] * res.number_of_iterations 
    517525 
     
    627635 
    628636    k = len(res.results[0].classes) 
    629     if (k<2): 
     637    if k<2: 
    630638        raise TypeError, "nothing to compare (less than two classifiers given)" 
    631639    if k==2: 
     
    656664        numberOfClasses = len(test_results.class_values) 
    657665        if class_index < -1 or numberOfClasses > 2: 
    658             cm = [[[0.0] * numberOfClasses for i in range(numberOfClasses)] for l in range(test_results.number_of_learners)] 
     666            cm = [[[0.0] * numberOfClasses for _ in range(numberOfClasses)] for _ in range(test_results.number_of_learners)] 
    659667            if ignore_weights or not test_results.weights: 
    660668                for tex in test_results.results: 
     
    920928       marginalSumOfColumns = numpy.sum(confusion_matrix, axis=1) 
    921929       jointProportion = (marginalSumOfColumns + marginalSumOfRows)/ \ 
    922                            (2.0 * numpy.sum(confusion_matrix, axis=None)) 
     930                           (2.0 * numpy.sum(confusion_matrix)) 
    923931       # In the eq. above, 2.0 is what the Wikipedia page calls 
    924932       # the number of annotators. Here we have two annotators: 
     
    926934       # the learners. 
    927935 
    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) 
    930938 
    931939       ret = (prActual - prExpected) / (1.0 - prExpected) 
     
    10231031        R.append(P) 
    10241032    else: 
    1025         while (1): 
     1033        while True: 
    10261034            if len(R) < 2: 
    10271035                R.append(P) 
     
    11101118    "A range function, that does accept float increments..." 
    11111119 
    1112     if end == None: 
     1120    if end is None: 
    11131121        end = start + 0.0 
    11141122        start = 0.0 
    11151123 
    1116     if inc == None or inc == 0: 
     1124    if inc is None or inc == 0: 
    11171125        inc = 1.0 
    11181126 
     
    11501158        while i < npts - 1: 
    11511159            (fp, _, _) = ROC[i + 1] 
    1152             if (fp <= FPsample): 
     1160            if fp <= FPsample: 
    11531161                i += 1 
    11541162            else: 
     
    11881196        stdev.append(TPstd) 
    11891197 
    1190     return (average, stdev) 
     1198    return average, stdev 
    11911199 
    11921200## input ROCcurves are of form [ROCcurves1, ROCcurves2, ... ROCcurvesN], 
     
    12021210        while i < npts - 1: 
    12031211            (px, py, pfscore) = ROC[i] 
    1204             if (pfscore > thresh): 
     1212            if pfscore > thresh: 
    12051213                i += 1 
    12061214            else: 
     
    13151323        else: 
    13161324            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 function 
     1325        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 
    13181326        results.append((curve, yesClassRugPoints, noClassRugPoints)) 
    13191327 
     
    13721380    weightByClasses = argkw.get("weightByClasses", True) 
    13731381 
    1374     if (res.number_of_iterations>1): 
     1382    if res.number_of_iterations>1: 
    13751383        CDTs = [CDT() for i in range(res.number_of_learners)] 
    13761384        iterationExperiments = split_by_iterations(res) 
     
    14511459                                             res.number_of_iterations)) 
    14521460                    if subsum_aucs: 
    1453                         if method == 0: 
     1461                        if method == self.ByWeightedPairs: 
    14541462                            p_ij = prob[classIndex1] * prob[classIndex2] 
    14551463                            subsum_aucs = [x * p_ij  for x in subsum_aucs] 
     
    14651473                                 res.number_of_iterations)) 
    14661474                if subsum_aucs: 
    1467                     if method == 0: 
     1475                    if method == self.ByWeightedPairs: 
    14681476                        p_i = prob[classIndex] 
    14691477                        subsum_aucs = [x * p_i  for x in subsum_aucs] 
     
    20382046    k = len(avranks) 
    20392047    
    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        , ("bonferroni-dunn", "0.05"): [0, 0, 1.960, 2.241, 2.394, 2.498, 2.576, 
     2057                                        2.638, 2.690, 2.724, 2.773], 
     2058         ("bonferroni-dunn", "0.1"): [0, 0, 1.645, 1.960, 2.128, 2.241, 2.326, 
     2059                                      2.394, 2.450, 2.498, 2.539]} 
    20412060 
    20422061    #can be computed in R as qtukey(0.95, n, Inf)**0.5 
    20432062    #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[("bonferroni-dunn", "0.05")] =  [0, 0, 1.960, 2.241, 2.394, 2.498, 2.576, 2.638, 2.690, 2.724, 2.773 ] 
    2048     d[("bonferroni-dunn", "0.1")] = [0, 0, 1.645, 1.960, 2.128, 2.241, 2.326, 2.394, 2.450, 2.498, 2.539 ] 
    20492063 
    20502064    q = d[(type, alpha)] 
     
    20762090    :param textspace: Space on figure sides left for the description 
    20772091                      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. 
    20792093    :param cdmethod: None by default. It can be an index of element in avranks 
    20802094                     or or names which specifies the method which should be 
    20812095                     marked with an interval. 
    20822096    """ 
     2097    if not HAS_MATPLOTLIB: 
     2098        import sys 
     2099        print >> sys.stderr, "Function requires matplotlib. Please install it." 
     2100        return 
    20832101 
    20842102    width = float(width) 
     
    21162134 
    21172135        """ 
    2118         if len(lr) == 0: 
     2136        if not len(lr): 
    21192137            yield () 
    21202138        else: 
     
    21272145                    yield tuple([a] + list(b)) 
    21282146 
    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 
    21372150 
    21382151    def print_figure(fig, *args, **kwargs): 
     
    22532266 
    22542267    for i in range((k+1)/2): 
    2255         chei = cline+ minnotsignificant + (i)*0.2 
     2268        chei = cline+ minnotsignificant + i *0.2 
    22562269        line([(rankpos(ssums[i]), cline), (rankpos(ssums[i]), chei), (textspace-0.1, chei)], linewidth=0.7) 
    22572270        text(textspace-0.2, chei, nnames[i], ha="right", va="center") 
Note: See TracChangeset for help on using the changeset viewer.