Changeset 9452:d9b12ff5aca3 in orange


Ignore:
Timestamp:
07/06/11 08:23:14 (3 years ago)
Author:
matija <matija.polajnar@…>
Branch:
default
Convert:
5806889840395b3e65f68d3f2d06c6bfde5d7244
Message:

MLC scoring/testing: ensure backward compatibility of refactored modules.

Location:
orange/Orange/evaluation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/evaluation/scoring.py

    r9450 r9452  
    511511        return [res] 
    512512         
    513     ress = [Orange.evaluation.testing.ExperimentResults(1, res.classifierNames, res.class_values, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
     513    ress = [Orange.evaluation.testing.ExperimentResults(1, res.classifier_names, res.class_values, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
    514514            for i in range(res.number_of_iterations)] 
    515515    for te in res.results: 
     
    16001600    import corn 
    16011601    ## merge multiple iterations into one 
    1602     mres = Orange.evaluation.testing.ExperimentResults(1, res.classifierNames, res.class_values, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
     1602    mres = Orange.evaluation.testing.ExperimentResults(1, res.classifier_names, res.class_values, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
    16031603    for te in res.results: 
    16041604        mres.results.append( te ) 
     
    16621662    import corn 
    16631663    ## merge multiple iterations into one 
    1664     mres = Orange.evaluation.testing.ExperimentResults(1, res.classifierNames, res.class_values, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
     1664    mres = Orange.evaluation.testing.ExperimentResults(1, res.classifier_names, res.class_values, res.weights, classifiers=res.classifiers, loaded=res.loaded) 
    16651665    for te in res.results: 
    16661666        mres.results.append( te ) 
  • orange/Orange/evaluation/testing.py

    r9450 r9452  
    3737    :end-before: def printResults(res) 
    3838 
    39 Example scripts for multi-label data. 
     39Testing can also be used on multi-label data. 
     40 
    4041part of `mlc-evaluator.py`_ (uses `multidata.tab`_) 
    4142 
     
    7980    if the class variable is discrete and has no unknown values. 
    8081 
    81 *randseed (obsolete: indices_randseed), randomGenerator* 
     82*randseed (obsolete: indicesrandseed), randomGenerator* 
    8283    Random seed (``randseed``) or random generator (``randomGenerator``) for 
    8384    random selection of examples. If omitted, random seed of 0 is used and 
     
    201202import Orange 
    202203from Orange.misc import demangleExamples, getobjectname, printVerbose 
    203 import exceptions, cPickle, os, os.path 
     204from Orange.misc import deprecated_keywords, deprecated_members 
    204205import Orange.multilabel.label as label  
     206 
     207import exceptions 
     208import cPickle 
     209import os 
     210import os.path 
    205211 
    206212#### Some private stuff 
     
    259265    """ 
    260266 
     267    @deprecated_keywords({"iterationNumber": "iteration_number", 
     268                          "actualClass": "actual_class"}) 
    261269    def __init__(self, iteration_number=None, actual_class=None, n=0, weight=1.0, multilabel_flag = 0): 
    262270        self.classes = [None]*n 
     
    288296            self.classes[i] = aclass 
    289297            self.probabilities[i] = list(aprob) 
     298 
     299TestedExample = deprecated_members({"iterationNumber": "iteration_number", 
     300                                    "actualClass": "actual_class" 
     301                                    })(TestedExample) 
    290302             
    291303class ExperimentResults(object): 
     
    336348 
    337349    """ 
     350    @deprecated_keywords({"classifierNames": "classifier_names", 
     351                          "classValues": "class_values", 
     352                          "baseClass": "base_class"}) 
    338353    def __init__(self, iterations, classifier_names, class_values, weights, base_class=-1, **argkw): 
    339354        self.class_values = class_values 
     
    451466                    self.classifiers[replace] = results.classifiers[i][index] 
    452467 
     468ExperimentResults = deprecated_members({"classValues": "class_values", 
     469                                        "classifierNames": "classifier_names", 
     470                                        "numberOfIterations": "number_of_iterations", 
     471                                        "numberOfLearners": "number_of_learners", 
     472                                        "baseClass": "base_class" 
     473                                        })(ExperimentResults) 
     474 
    453475#### Experimental procedures 
    454476 
    455 def leave_one_out(learners, examples, pps=[], indices_randseed="*", **argkw): 
     477def leave_one_out(learners, examples, pps=[], indicesrandseed="*", **argkw): 
    456478 
    457479    """leave-one-out evaluation of learners on a data set 
     
    465487 
    466488    (examples, weight) = demangleExamples(examples) 
    467     return test_with_indices(learners, examples, range(len(examples)), indices_randseed, pps, **argkw) 
     489    return test_with_indices(learners, examples, range(len(examples)), indicesrandseed, pps, **argkw) 
    468490    # return test_with_indices(learners, examples, range(len(examples)), pps=pps, argkw) 
    469491 
    470 # apply(test_with_indices, (learners, (examples, weight), indices, indices_randseed, pps), argkw) 
     492# apply(test_with_indices, (learners, (examples, weight), indices, indicesrandseed, pps), argkw) 
    471493 
    472494 
     
    496518    # randomGenerator is set either to what users provided or to orange.RandomGenerator(0) 
    497519    # If we left it None or if we set MakeRandomIndices2.randseed, it would give same indices each time it's called 
    498     randomGenerator = argkw.get("indices_randseed", 0) or argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
     520    randomGenerator = argkw.get("indicesrandseed", 0) or argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
    499521    pick = Orange.core.MakeRandomIndices2(stratified = strat, p0 = learnProp, randomGenerator = randomGenerator) 
    500522     
     
    518540def cross_validation(learners, examples, folds=10, 
    519541                    strat=Orange.core.MakeRandomIndices.StratifiedIfPossible, 
    520                     pps=[], indices_randseed="*", **argkw): 
     542                    pps=[], indicesrandseed="*", **argkw): 
    521543    """cross-validation evaluation of learners 
    522544 
     
    525547    """ 
    526548    (examples, weight) = demangleExamples(examples) 
    527     if indices_randseed!="*": 
    528         indices = Orange.core.MakeRandomIndicesCV(examples, folds, randseed=indices_randseed, stratified = strat) 
     549    if indicesrandseed!="*": 
     550        indices = Orange.core.MakeRandomIndicesCV(examples, folds, randseed=indicesrandseed, stratified = strat) 
    529551    else: 
    530552        randomGenerator = argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
    531553        indices = Orange.core.MakeRandomIndicesCV(examples, folds, stratified = strat, randomGenerator = randomGenerator) 
    532     return test_with_indices(learners, (examples, weight), indices, indices_randseed, pps, **argkw) 
     554    return test_with_indices(learners, (examples, weight), indices, indicesrandseed, pps, **argkw) 
    533555 
    534556 
     
    555577    """ 
    556578 
    557     seed = argkw.get("indices_randseed", -1) or argkw.get("randseed", -1) 
     579    seed = argkw.get("indicesrandseed", -1) or argkw.get("randseed", -1) 
    558580    if seed: 
    559581        randomGenerator = Orange.core.RandomGenerator(seed) 
     
    601623 
    602624    if not cv or not pick:     
    603         seed = argkw.get("indices_randseed", -1) or argkw.get("randseed", -1) 
     625        seed = argkw.get("indicesrandseed", -1) or argkw.get("randseed", -1) 
    604626        if seed: 
    605627            randomGenerator = Orange.core.RandomGenerator(seed) 
     
    701723    testweight = demangleExamples(testset)[1] 
    702724     
    703     randomGenerator = argkw.get("indices_randseed", 0) or argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
     725    randomGenerator = argkw.get("indicesrandseed", 0) or argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
    704726    pick = Orange.core.MakeRandomIndices2(stratified = strat, randomGenerator = randomGenerator) 
    705727    allResults=[] 
     
    721743 
    722744    
    723 def test_with_indices(learners, examples, indices, indices_randseed="*", pps=[], callback=None, **argkw): 
     745def test_with_indices(learners, examples, indices, indicesrandseed="*", pps=[], callback=None, **argkw): 
    724746    """ 
    725747    Performs a cross-validation-like test. The difference is that the 
     
    734756    saved in files or loaded therefrom if you add a keyword argument 
    735757    ``cache=1``. In this case, you also have to specify the random seed 
    736     which was used to compute the indices (argument ``indices_randseed``; 
     758    which was used to compute the indices (argument ``indicesrandseed``; 
    737759    if you don't there will be no caching. 
    738760 
     
    741763    verb = argkw.get("verbose", 0) 
    742764    cache = argkw.get("cache", 0) 
    743     store_classifiers = argkw.get("store_classifiers", 0) or argkw.get("store_classifiers", 0) 
     765    store_classifiers = argkw.get("storeclassifiers", 0) or argkw.get("store_classifiers", 0) or argkw.get("storeClassifiers", 0) 
    744766    cache = cache and not store_classifiers 
    745767 
     
    753775    multilabel_flag = label.is_multilabel(examples) 
    754776     
    755     if multilabel_flag == 0 and not examples.domain.classVar: #single-label 
     777    if multilabel_flag == 0 and not examples.domain.classvar: #single-label 
    756778        raise ValueError("Test data set without class attribute") 
    757779     
     
    762784    nIterations = max(indices)+1 
    763785    if multilabel_flag == 0: #single-label 
    764         if examples.domain.classVar.varType == Orange.data.Type.Discrete: 
    765             values = list(examples.domain.classVar.values) 
    766             basevalue = examples.domain.classVar.baseValue 
     786        if examples.domain.classvar.vartype == Orange.data.Type.Discrete: 
     787            values = list(examples.domain.classvar.values) 
     788            basevalue = examples.domain.classvar.basevalue 
    767789        else: 
    768790            basevalue = values = None 
     
    785807    ccsum = hex(examples.checksum())[2:] 
    786808    ppsp = encode_PP(pps) 
    787     fnstr = "{TestWithIndices}_%s_%s%s-%s" % ("%s", indices_randseed, ppsp, ccsum) 
     809    fnstr = "{TestWithIndices}_%s_%s%s-%s" % ("%s", indicesrandseed, ppsp, ccsum) 
    788810    if "*" in fnstr: 
    789811        cache = 0 
     
    850872 
    851873 
     874@deprecated_keywords({"testResults": "test_results", 
     875                      "iterationNumber": "iteration_number"}) 
    852876def learn_and_test_on_test_data(learners, learnset, testset, test_results=None, iteration_number=0, pps=[], callback=None, **argkw): 
    853877    """ 
     
    869893 
    870894    """ 
    871     store_classifiers = argkw.get("store_classifiers", 0) or argkw.get("store_classifiers", 0) 
    872     storeExamples = argkw.get("storeExamples", 0) 
     895    store_classifiers = argkw.get("storeclassifiers", 0) or argkw.get("store_classifiers", 0) or argkw.get("storeClassifiers", 0) 
     896    store_examples = argkw.get("store_examples", 0) or argkw.get("storeExamples", 0) 
    873897 
    874898    learnset, learnweight = demangleExamples(learnset) 
    875899    testset, testweight = demangleExamples(testset) 
    876     store_classifiers = argkw.get("store_classifiers", 0) or argkw.get("store_classifiers", 0) 
     900    store_classifiers = argkw.get("storeclassifiers", 0) or argkw.get("store_classifiers", 0) or argkw.get("storeClassifiers", 0) 
    877901     
    878902    for pp in pps: 
     
    896920    for i in range(len(learners)): 
    897921        classifiers[i].name = getattr(learners[i], 'name', 'noname') 
    898     test_results = test_on_data(classifiers, (testset, testweight), test_results, iteration_number, storeExamples) 
     922    test_results = test_on_data(classifiers, (testset, testweight), test_results, iteration_number, store_examples) 
    899923    if store_classifiers: 
    900924        test_results.classifiers.append(classifiers) 
     
    902926 
    903927 
     928@deprecated_keywords({"testResults": "test_results", 
     929                      "iterationNumber": "iteration_number"}) 
    904930def learn_and_test_on_learn_data(learners, learnset, test_results=None, iteration_number=0, pps=[], callback=None, **argkw): 
    905931    """ 
     
    917943    """ 
    918944 
    919     store_classifiers = argkw.get("store_classifiers", 0) or argkw.get("store_classifiers", 0) 
    920     storeExamples = argkw.get("storeExamples", 0) 
     945    store_classifiers = argkw.get("storeclassifiers", 0) or argkw.get("store_classifiers", 0) or argkw.get("storeClassifiers", 0) 
     946    store_examples = argkw.get("store_examples", 0) or argkw.get("store_examples", 0) 
    921947 
    922948    learnset, learnweight = demangleExamples(learnset) 
     
    948974    for i in range(len(learners)): 
    949975        classifiers[i].name = getattr(learners[i], "name", "noname") 
    950     test_results = test_on_data(classifiers, (testset, learnweight), test_results, iteration_number, storeExamples) 
     976    test_results = test_on_data(classifiers, (testset, learnweight), 
     977                                test_results, iteration_number, store_examples) 
    951978    if store_classifiers: 
    952979        test_results.classifiers.append(classifiers) 
     
    954981 
    955982 
    956 def test_on_data(classifiers, testset, test_results=None, iteration_number=0, storeExamples = False, **argkw): 
     983@deprecated_keywords({"testResults": "test_results", 
     984                      "iterationNumber": "iteration_number", 
     985                      "storeExamples": "store_examples"}) 
     986def test_on_data(classifiers, testset, test_results=None, iteration_number=0, store_examples = False, **argkw): 
    957987    """ 
    958988    This function gets a list of classifiers, not learners like the other 
     
    9751005            values = None 
    9761006            baseValue = -1 
    977         test_results=ExperimentResults(1, [l.name for l in classifiers], values, testweight!=0, baseValue) 
     1007        test_results=ExperimentResults(1, [l.name for l in classifiers], values, 
     1008                                       testweight!=0, baseValue) 
    9781009 
    9791010    examples = getattr(test_results, "examples", False) 
     
    9911022    conv = testset.domain.classVar.varType == Orange.data.Type.Discrete and int or float 
    9921023    for ex in testset: 
    993         te = TestedExample(iteration_number, conv(ex.getclass()), 0, ex.getweight(testweight)) 
     1024        te = TestedExample(iteration_number, conv(ex.getclass()), 0, 
     1025                           ex.getweight(testweight)) 
    9941026 
    9951027        for classifier in classifiers: 
Note: See TracChangeset for help on using the changeset viewer.