Changeset 7413:06dd273e3f39 in orange


Ignore:
Timestamp:
02/04/11 12:11:41 (3 years ago)
Author:
jzbontar <jure.zbontar@…>
Branch:
default
Convert:
48db600c12120d123ff91ba1a8cc1eb9232d5151
Message:

added Orange.evaluation.testing

Location:
orange
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/__init__.py

    r7408 r7413  
    6262import evaluation 
    6363import evaluation.scoring 
     64import evaluation.testing 
    6465 
    6566import cluster 
  • orange/Orange/classification/logreg.py

    r7339 r7413  
    1919.. autofunction:: LogRegLearner 
    2020.. autofunction:: StepWiseFSS 
    21 .. autofunction:: printOUT 
     21.. autofunction:: dump 
    2222 
    2323 
     
    182182""" 
    183183 
    184 from orange import LogRegLearner, LogRegClassifier, LogRegFitter, LogRegFitter_Cholesky 
    185  
    186 import orange 
    187 import orngCI 
     184from Orange.core import LogRegLearner, LogRegClassifier, LogRegFitter, LogRegFitter_Cholesky 
     185 
     186import Orange 
    188187import math, os 
    189188import warnings 
     
    195194## Print out methods ## 
    196195####################### 
    197 def printOUT(classifier): 
    198     warnings.warn("printOut is deprecated, use dump instead.", DeprecationWarning) 
    199     dump(classifier) 
    200  
    201196def dump(classifier): 
    202197    """ Formatted print to console of all major features in logistic 
     
    231226def hasDiscreteValues(domain): 
    232227    for at in domain.attributes: 
    233         if at.varType == orange.VarTypes.Discrete: 
     228        if at.varType == Orange.core.VarTypes.Discrete: 
    234229            return 1 
    235230    return 0 
     
    248243    :param removeSingular: set to 1 if you want automatic removal of disturbing features, such as constants and singularities 
    249244    :type removeSingular: bool 
    250     :param fitter: alternate the fitting algorithm (currently the Newton-Raphson fitting algorithm is used) 
     245    :param fitter: the fitting algorithm (by default the Newton-Raphson fitting algorithm is used) 
    251246    :type fitter: type??? 
    252247    :param stepwiseLR: set to 1 if you wish to use stepwise logistic regression 
     
    267262        return lr 
    268263 
    269 class LogRegLearnerClass(orange.Learner): 
     264class LogRegLearnerClass(Orange.core.Learner): 
    270265    def __init__(self, removeSingular=0, fitter = None, **kwds): 
    271266        self.__dict__.update(kwds) 
     
    276271        imputer = getattr(self, "imputer", None) or None 
    277272        if getattr(self, "removeMissing", 0): 
    278             examples = orange.Preprocessor_dropMissing(examples) 
     273            examples = Orange.core.Preprocessor_dropMissing(examples) 
    279274##        if hasDiscreteValues(examples.domain): 
    280275##            examples = createNoDiscTable(examples) 
     
    286281            numFeatures = getattr(self, "numFeatures", -1) 
    287282            attributes = StepWiseFSS(examples, addCrit = addCrit, deleteCrit = removeCrit, imputer = imputer, numFeatures = numFeatures) 
    288             tmpDomain = orange.Domain(attributes, examples.domain.classVar) 
     283            tmpDomain = Orange.core.Domain(attributes, examples.domain.classVar) 
    289284            tmpDomain.addmetas(examples.domain.getmetas()) 
    290285            examples = examples.select(tmpDomain) 
    291         learner = orange.LogRegLearner() 
     286        learner = Orange.core.LogRegLearner() 
    292287        learner.imputerConstructor = imputer 
    293288        if imputer: 
    294289            examples = self.imputer(examples)(examples) 
    295         examples = orange.Preprocessor_dropMissing(examples) 
     290        examples = Orange.core.Preprocessor_dropMissing(examples) 
    296291        if self.fitter: 
    297292            learner.fitter = self.fitter 
     
    300295        else: 
    301296            lr = learner(examples, weight) 
    302         while isinstance(lr, orange.Variable): 
    303             if isinstance(lr.getValueFrom, orange.ClassifierFromVar) and isinstance(lr.getValueFrom.transformer, orange.Discrete2Continuous): 
     297        while isinstance(lr, Orange.core.Variable): 
     298            if isinstance(lr.getValueFrom, Orange.core.ClassifierFromVar) and isinstance(lr.getValueFrom.transformer, Orange.core.Discrete2Continuous): 
    304299                lr = lr.getValueFrom.variable 
    305300            attributes = examples.domain.attributes[:] 
     
    308303            else: 
    309304                attributes.remove(lr.getValueFrom.variable) 
    310             newDomain = orange.Domain(attributes, examples.domain.classVar) 
     305            newDomain = Orange.core.Domain(attributes, examples.domain.classVar) 
    311306            newDomain.addmetas(examples.domain.getmetas()) 
    312307            examples = examples.select(newDomain) 
     
    323318        return learner 
    324319 
    325 class Univariate_LogRegLearner_Class(orange.Learner): 
     320class Univariate_LogRegLearner_Class(Orange.core.Learner): 
    326321    def __init__(self, **kwds): 
    327322        self.__dict__.update(kwds) 
     
    329324    def __call__(self, examples): 
    330325        examples = createFullNoDiscTable(examples) 
    331         classifiers = map(lambda x: LogRegLearner(orange.Preprocessor_dropMissing(examples.select(orange.Domain(x, examples.domain.classVar)))), examples.domain.attributes) 
    332         maj_classifier = LogRegLearner(orange.Preprocessor_dropMissing(examples.select(orange.Domain(examples.domain.classVar)))) 
     326        classifiers = map(lambda x: LogRegLearner(Orange.core.Preprocessor_dropMissing(examples.select(Orange.core.Domain(x, examples.domain.classVar)))), examples.domain.attributes) 
     327        maj_classifier = LogRegLearner(Orange.core.Preprocessor_dropMissing(examples.select(Orange.core.Domain(examples.domain.classVar)))) 
    333328        beta = [maj_classifier.beta[0]] + [x.beta[1] for x in classifiers] 
    334329        beta_se = [maj_classifier.beta_se[0]] + [x.beta_se[1] for x in classifiers] 
     
    339334        return Univariate_LogRegClassifier(beta = beta, beta_se = beta_se, P = P, wald_Z = wald_Z, domain = domain) 
    340335 
    341 class Univariate_LogRegClassifier(orange.Classifier): 
     336class Univariate_LogRegClassifier(Orange.core.Classifier): 
    342337    def __init__(self, **kwds): 
    343338        self.__dict__.update(kwds) 
    344339 
    345     def __call__(self, example, resultType = orange.GetValue): 
     340    def __call__(self, example, resultType = Orange.core.GetValue): 
    346341        # classification not implemented yet. For now its use is only to provide regression coefficients and its statistics 
    347342        pass 
     
    366361                # za vsak atribut kreiraj nov newExampleTable newData 
    367362                # v dataOrig, dataFinal in newData dodaj nov atribut -- continuous variable 
    368                 if at.varType == orange.VarTypes.Continuous: 
    369                     atDisc = orange.FloatVariable(at.name + "Disc") 
    370                     newDomain = orange.Domain(data.domain.attributes+[atDisc,data.domain.classVar]) 
     363                if at.varType == Orange.core.VarTypes.Continuous: 
     364                    atDisc = Orange.core.FloatVariable(at.name + "Disc") 
     365                    newDomain = Orange.core.Domain(data.domain.attributes+[atDisc,data.domain.classVar]) 
    371366                    newDomain.addmetas(data.domain.getmetas()) 
    372                     newData = orange.ExampleTable(newDomain,data) 
    373                     altData = orange.ExampleTable(newDomain,data) 
     367                    newData = Orange.core.ExampleTable(newDomain,data) 
     368                    altData = Orange.core.ExampleTable(newDomain,data) 
    374369                    for i,d in enumerate(newData): 
    375370                        d[atDisc] = 0 
     
    379374                        d[at] = 0 
    380375                        d[weightID] = 0.000001*data[i][weightID] 
    381                 elif at.varType == orange.VarTypes.Discrete: 
     376                elif at.varType == Orange.core.VarTypes.Discrete: 
    382377                # v dataOrig, dataFinal in newData atributu "at" dodaj ee  eno  vreednost, ki ima vrednost kar  ime atributa +  "X" 
    383                     atNew = orange.EnumVariable(at.name, values = at.values + [at.name+"X"]) 
    384                     newDomain = orange.Domain(filter(lambda x: x!=at, data.domain.attributes)+[atNew,data.domain.classVar]) 
     378                    atNew = Orange.core.EnumVariable(at.name, values = at.values + [at.name+"X"]) 
     379                    newDomain = Orange.core.Domain(filter(lambda x: x!=at, data.domain.attributes)+[atNew,data.domain.classVar]) 
    385380                    newDomain.addmetas(data.domain.getmetas()) 
    386                     newData = orange.ExampleTable(newDomain,data) 
    387                     altData = orange.ExampleTable(newDomain,data) 
     381                    newData = Orange.core.ExampleTable(newDomain,data) 
     382                    altData = Orange.core.ExampleTable(newDomain,data) 
    388383                    for i,d in enumerate(newData): 
    389384                        d[atNew] = data[i][at] 
     
    396391            return setsOfData 
    397392                   
    398         learner = LogRegLearner(imputer = orange.ImputerConstructor_average(), removeSingular = self.removeSingular) 
     393        learner = LogRegLearner(imputer = Orange.core.ImputerConstructor_average(), removeSingular = self.removeSingular) 
    399394        # get Original Model 
    400395        orig_model = learner(examples,weight) 
     
    404399        # get extended Model (you should not change data) 
    405400        if weight == 0: 
    406             weight = orange.newmetaid() 
     401            weight = Orange.core.newmetaid() 
    407402            examples.addMetaAttribute(weight, 1.0) 
    408403        extended_set_of_examples = createLogRegExampleTable(examples, weight) 
     
    434429         
    435430        # compare it to bayes prior 
    436         bayes = orange.BayesLearner(examples) 
     431        bayes = Orange.core.BayesLearner(examples) 
    437432        bayes_prior = math.log(bayes.distribution[1]/bayes.distribution[0]) 
    438433 
     
    441436##        print "lr", orig_model.beta[0] 
    442437##        print "lr2", logistic_prior 
    443 ##        print "dist", orange.Distribution(examples.domain.classVar,examples) 
     438##        print "dist", Orange.core.Distribution(examples.domain.classVar,examples) 
    444439##        print "prej", betas_ap 
    445440 
     
    473468        # next function changes data set to a extended with unknown values  
    474469        def createLogRegExampleTable(data, weightID): 
    475             finalData = orange.ExampleTable(data) 
    476             origData = orange.ExampleTable(data) 
     470            finalData = Orange.core.ExampleTable(data) 
     471            origData = Orange.core.ExampleTable(data) 
    477472            for at in data.domain.attributes: 
    478473                # za vsak atribut kreiraj nov newExampleTable newData 
    479474                # v dataOrig, dataFinal in newData dodaj nov atribut -- continuous variable 
    480                 if at.varType == orange.VarTypes.Continuous: 
    481                     atDisc = orange.FloatVariable(at.name + "Disc") 
    482                     newDomain = orange.Domain(origData.domain.attributes+[atDisc,data.domain.classVar]) 
     475                if at.varType == Orange.core.VarTypes.Continuous: 
     476                    atDisc = Orange.core.FloatVariable(at.name + "Disc") 
     477                    newDomain = Orange.core.Domain(origData.domain.attributes+[atDisc,data.domain.classVar]) 
    483478                    newDomain.addmetas(newData.domain.getmetas()) 
    484                     finalData = orange.ExampleTable(newDomain,finalData) 
    485                     newData = orange.ExampleTable(newDomain,origData) 
    486                     origData = orange.ExampleTable(newDomain,origData) 
     479                    finalData = Orange.core.ExampleTable(newDomain,finalData) 
     480                    newData = Orange.core.ExampleTable(newDomain,origData) 
     481                    origData = Orange.core.ExampleTable(newDomain,origData) 
    487482                    for d in origData: 
    488483                        d[atDisc] = 0 
     
    494489                        d[weightID] = 100*data[i][weightID] 
    495490                         
    496                 elif at.varType == orange.VarTypes.Discrete: 
     491                elif at.varType == Orange.core.VarTypes.Discrete: 
    497492                # v dataOrig, dataFinal in newData atributu "at" dodaj ee  eno  vreednost, ki ima vrednost kar  ime atributa +  "X" 
    498                     atNew = orange.EnumVariable(at.name, values = at.values + [at.name+"X"]) 
    499                     newDomain = orange.Domain(filter(lambda x: x!=at, origData.domain.attributes)+[atNew,origData.domain.classVar]) 
     493                    atNew = Orange.core.EnumVariable(at.name, values = at.values + [at.name+"X"]) 
     494                    newDomain = Orange.core.Domain(filter(lambda x: x!=at, origData.domain.attributes)+[atNew,origData.domain.classVar]) 
    500495                    newDomain.addmetas(origData.domain.getmetas()) 
    501                     temp_finalData = orange.ExampleTable(finalData) 
    502                     finalData = orange.ExampleTable(newDomain,finalData) 
    503                     newData = orange.ExampleTable(newDomain,origData) 
    504                     temp_origData = orange.ExampleTable(origData) 
    505                     origData = orange.ExampleTable(newDomain,origData) 
     496                    temp_finalData = Orange.core.ExampleTable(finalData) 
     497                    finalData = Orange.core.ExampleTable(newDomain,finalData) 
     498                    newData = Orange.core.ExampleTable(newDomain,origData) 
     499                    temp_origData = Orange.core.ExampleTable(origData) 
     500                    origData = Orange.core.ExampleTable(newDomain,origData) 
    506501                    for i,d in enumerate(origData): 
    507502                        d[atNew] = temp_origData[i][at] 
     
    514509            return finalData 
    515510                   
    516         learner = LogRegLearner(imputer = orange.ImputerConstructor_average(), removeSingular = self.removeSingular) 
     511        learner = LogRegLearner(imputer = Orange.core.ImputerConstructor_average(), removeSingular = self.removeSingular) 
    517512        # get Original Model 
    518513        orig_model = learner(examples,weight) 
     
    520515        # get extended Model (you should not change data) 
    521516        if weight == 0: 
    522             weight = orange.newmetaid() 
     517            weight = Orange.core.newmetaid() 
    523518            examples.addMetaAttribute(weight, 1.0) 
    524519        extended_examples = createLogRegExampleTable(examples, weight) 
     
    545540         
    546541        # compare it to bayes prior 
    547         bayes = orange.BayesLearner(examples) 
     542        bayes = Orange.core.BayesLearner(examples) 
    548543        bayes_prior = math.log(bayes.distribution[1]/bayes.distribution[0]) 
    549544 
     
    552547        #print "lr", orig_model.beta[0] 
    553548        #print "lr2", logistic_prior 
    554         #print "dist", orange.Distribution(examples.domain.classVar,examples) 
     549        #print "dist", Orange.core.Distribution(examples.domain.classVar,examples) 
    555550        k = (bayes_prior-orig_model.beta[0])/(logistic_prior-orig_model.beta[0]) 
    556551        #print "prej", betas_ap 
     
    585580    return mat 
    586581     
    587 class simpleFitter(orange.LogRegFitter): 
     582class simpleFitter(Orange.core.LogRegFitter): 
    588583    def __init__(self, penalty=0, se_penalty = False): 
    589584        self.penalty = penalty 
     
    593588        for i in range(len(data.domain.attributes)): 
    594589          a = data.domain.attributes[i] 
    595           if a.varType == orange.VarTypes.Discrete: 
     590          if a.varType == Orange.core.VarTypes.Discrete: 
    596591            for m in ml: 
    597592              m[i] = a.values.index(m[i]) 
     
    672667    return exp(bx)/(1+exp(bx)) 
    673668 
    674 class bayesianFitter(orange.LogRegFitter): 
     669class bayesianFitter(Orange.core.LogRegFitter): 
    675670    def __init__(self, penalty=0, anch_examples=[], tau = 0): 
    676671        self.penalty = penalty 
     
    684679        ml = data.native(0) 
    685680        for i,a in enumerate(data.domain.attributes): 
    686           if a.varType == orange.VarTypes.Discrete: 
     681          if a.varType == Orange.core.VarTypes.Discrete: 
    687682            for m in ml: 
    688683              m[i] = a.values.index(m[i]) 
     
    698693        (X,y)=self.createArrayData(data) 
    699694 
    700         exTable = orange.ExampleTable(data.domain) 
     695        exTable = Orange.core.ExampleTable(data.domain) 
    701696        for id,ex in self.anch_examples: 
    702             exTable.extend(orange.ExampleTable(ex,data.domain)) 
     697            exTable.extend(Orange.core.ExampleTable(ex,data.domain)) 
    703698        (X_anch,y_anch)=self.createArrayData(exTable) 
    704699 
     
    728723            print "betas", betas[0], betas_temp[0] 
    729724            sumB += betas[0]-betas_temp[0] 
    730         apriori = orange.Distribution(data.domain.classVar, data) 
     725        apriori = Orange.core.Distribution(data.domain.classVar, data) 
    731726        aprioriProb = apriori[0]/apriori.abs 
    732727         
     
    862857 
    863858 
    864 class StepWiseFSS_class(orange.Learner): 
     859class StepWiseFSS_class(Orange.core.Learner): 
    865860  """ Perform stepwise logistic regression and return a list of the 
    866861  most "informative" features. Each step of the algorithm is composed 
     
    894889        examples = self.imputer(examples)(examples) 
    895890    if getattr(self, "removeMissing", 0): 
    896         examples = orange.Preprocessor_dropMissing(examples) 
    897     continuizer = orange.DomainContinuizer(zeroBased=1,continuousTreatment=orange.DomainContinuizer.Leave, 
    898                                            multinomialTreatment = orange.DomainContinuizer.FrequentIsBase, 
    899                                            classTreatment = orange.DomainContinuizer.Ignore) 
     891        examples = Orange.core.Preprocessor_dropMissing(examples) 
     892    continuizer = Orange.core.DomainContinuizer(zeroBased=1,continuousTreatment=Orange.core.DomainContinuizer.Leave, 
     893                                           multinomialTreatment = Orange.core.DomainContinuizer.FrequentIsBase, 
     894                                           classTreatment = Orange.core.DomainContinuizer.Ignore) 
    900895    attr = [] 
    901896    remain_attr = examples.domain.attributes[:] 
    902897 
    903898    # get LL for Majority Learner  
    904     tempDomain = orange.Domain(attr,examples.domain.classVar) 
    905     #tempData  = orange.Preprocessor_dropMissing(examples.select(tempDomain)) 
    906     tempData  = orange.Preprocessor_dropMissing(examples.select(tempDomain)) 
    907  
    908     ll_Old = getLikelihood(orange.LogRegFitter_Cholesky(), tempData) 
     899    tempDomain = Orange.core.Domain(attr,examples.domain.classVar) 
     900    #tempData  = Orange.core.Preprocessor_dropMissing(examples.select(tempDomain)) 
     901    tempData  = Orange.core.Preprocessor_dropMissing(examples.select(tempDomain)) 
     902 
     903    ll_Old = getLikelihood(Orange.core.LogRegFitter_Cholesky(), tempData) 
    909904    ll_Best = -1000000 
    910905    length_Old = float(len(tempData)) 
     
    924919 
    925920                tempAttr = filter(lambda x: x!=at, attr) 
    926                 tempDomain = orange.Domain(tempAttr,examples.domain.classVar) 
     921                tempDomain = Orange.core.Domain(tempAttr,examples.domain.classVar) 
    927922                tempDomain.addmetas(examples.domain.getmetas()) 
    928923                # domain, calculate P for LL improvement. 
    929                 tempDomain  = continuizer(orange.Preprocessor_dropMissing(examples.select(tempDomain))) 
    930                 tempData = orange.Preprocessor_dropMissing(examples.select(tempDomain)) 
    931  
    932                 ll_Delete = getLikelihood(orange.LogRegFitter_Cholesky(), tempData) 
     924                tempDomain  = continuizer(Orange.core.Preprocessor_dropMissing(examples.select(tempDomain))) 
     925                tempData = Orange.core.Preprocessor_dropMissing(examples.select(tempDomain)) 
     926 
     927                ll_Delete = getLikelihood(Orange.core.LogRegFitter_Cholesky(), tempData) 
    933928                length_Delete = float(len(tempData)) 
    934929                length_Avg = (length_Delete + length_Old)/2.0 
     
    944939            # deletion of attribute 
    945940             
    946             if worstAt.varType==orange.VarTypes.Continuous: 
     941            if worstAt.varType==Orange.core.VarTypes.Continuous: 
    947942                P=lchisqprob(minG,1); 
    948943            else: 
     
    971966        for at in remain_attr: 
    972967            tempAttr = attr + [at] 
    973             tempDomain = orange.Domain(tempAttr,examples.domain.classVar) 
     968            tempDomain = Orange.core.Domain(tempAttr,examples.domain.classVar) 
    974969            tempDomain.addmetas(examples.domain.getmetas()) 
    975970            # domain, calculate P for LL improvement. 
    976             tempDomain  = continuizer(orange.Preprocessor_dropMissing(examples.select(tempDomain))) 
    977             tempData = orange.Preprocessor_dropMissing(examples.select(tempDomain)) 
    978             ll_New = getLikelihood(orange.LogRegFitter_Cholesky(), tempData) 
     971            tempDomain  = continuizer(Orange.core.Preprocessor_dropMissing(examples.select(tempDomain))) 
     972            tempData = Orange.core.Preprocessor_dropMissing(examples.select(tempDomain)) 
     973            ll_New = getLikelihood(Orange.core.LogRegFitter_Cholesky(), tempData) 
    979974 
    980975            length_New = float(len(tempData)) # get number of examples in tempData to normalize likelihood 
     
    992987            continue 
    993988         
    994         if bestAt.varType==orange.VarTypes.Continuous: 
     989        if bestAt.varType==Orange.core.VarTypes.Continuous: 
    995990            P=lchisqprob(maxG,1); 
    996991        else: 
     
    10281023    def __call__(self, examples): 
    10291024        attr = StepWiseFSS(examples, addCrit=self.addCrit, deleteCrit = self.deleteCrit, numFeatures = self.numFeatures) 
    1030         return examples.select(orange.Domain(attr, examples.domain.classVar)) 
     1025        return examples.select(Orange.core.Domain(attr, examples.domain.classVar)) 
    10311026                 
    10321027 
  • orange/doc/Orange/rst/code/logreg-run.py

    r7339 r7413  
    1010        correct += 1 
    1111print "Classification accuracy:", correct / len(table) 
    12 classification.logreg.printOUT(lr) 
     12classification.logreg.dump(lr) 
  • orange/doc/Orange/rst/code/logreg-singularities.py

    r7292 r7413  
    66for ex in table[:5]: 
    77    print ex.getclass(), lr(ex) 
    8 classification.logreg.printOUT(lr) 
     8classification.logreg.dump(lr) 
  • orange/doc/Orange/rst/index.rst

    r7401 r7413  
    3737 
    3838   Orange.evaluation.scoring 
     39   Orange.evaluation.testing 
    3940 
    4041Indices and tables 
  • orange/doc/networks/network_info.tab

    r6641 r7413  
    33                                 
    44Air traffic network airtraffic.net  doc/datasets/   airtraffic_items.tab    ""  749 7688    4/12/2010   Nodes represent airports. Two nodes are connected if a direct flight between them exists. 
     5Leukemia genes connected by PubMed co-reference leu_by_pmid.net doc/datasets/   leu_by_pmid_items.tab   ""  253 1360    4/12/2010   The gene similarities are calculated based on common reference in articles form the PubMed using the Jaccard index. Two genes are similar if they are referenced together in several PubMed articles. The similarity threshold was set to 0.5. 
     6Similar music artists   last.fm.net doc/datasets/   last.fm_items.tab   ""  1239    7926    4/12/2010   Nodes represent music artists. Two artists are connected if they are in the top 5 similar artist list on the last.fm internet radio. 
     7PPI network mips_c2_cp_leu.net  doc/datasets/   mips_c2_cp_leu_items.tab    ""  132 242 4/12/2010   Protein-protein interaction network: theleukemia genes were connected into the network based on their protein interactions from the MIPS mammalian protein-protein interaction database. In addition, we used the biological function similarity score for placing the interacting protein components based on the similar biological functions of the proteins comprising them. 
     8Leukemia genes connected by Huttenhower score   leu_huttenhower_a.net   doc/datasets/   leu_huttenhower_a_items.tab ""  240 446 4/12/2010   The similarity between genes as computed by Huttenhower et al., 2009 using the information on all publicly available gene expression and protein interaction data, combined with prior knowledge from the Gene Ontology, KEGG, HPRD and other biological data bases. The threshold for similarity was set to 0.999. 
    59D. discoideum gene publication network  dicty_publication.net   doc/datasets/   dicty_publication_items.tab dicty_publication_edges.tab 385 6394    4/12/2010   Network from Dictyostelium discoideum gene and publication data. It contains nodes of two types: genes and MeSH terms. Edges connect: genes that were cited in similar publications, MeSH terms that were used to annotate the same publications, and genes to MeSH terms which were used to annotate publications citing the genes. 
    6 Similar music artists   last.fm.net doc/datasets/   last.fm_items.tab   ""  1239    7926    4/12/2010   Nodes represent music artists. Two artists are connected if they are in the top 5 similar artist list on the last.fm internet radio. 
    710Leukemia genes connected by biological function leu_by_genesets.net doc/datasets/   leu_by_genesets_items.tab   ""  72  146 4/12/2010   The similarity of the genes relates to their biological functions and was calculated based on their membership in canonical biological pathways using the Jaccard index. The information on the membership of genes in biological pathways was acquired from the Molecular Signature Database  
    8 Leukemia genes connected by PubMed co-reference leu_by_pmid.net doc/datasets/   leu_by_pmid_items.tab   ""  253 1360    4/12/2010   The gene similarities are calculated based on common reference in articles form the PubMed using the Jaccard index. Two genes are similar if they are referenced together in several PubMed articles. The similarity threshold was set to 0.5. 
    9 Leukemia genes connected by Huttenhower score   leu_huttenhower_a.net   doc/datasets/   leu_huttenhower_a_items.tab ""  240 446 4/12/2010   The similarity between genes as computed by Huttenhower et al., 2009 using the information on all publicly available gene expression and protein interaction data, combined with prior knowledge from the Gene Ontology, KEGG, HPRD and other biological data bases. The threshold for similarity was set to 0.999. 
    10 PPI network mips_c2_cp_leu.net  doc/datasets/   mips_c2_cp_leu_items.tab    ""  132 242 4/12/2010   Protein-protein interaction network: theleukemia genes were connected into the network based on their protein interactions from the MIPS mammalian protein-protein interaction database. In addition, we used the biological function similarity score for placing the interacting protein components based on the similar biological functions of the proteins comprising them. 
  • orange/orngLR.py

    r7205 r7413  
    11from Orange.classification.logreg import * 
     2 
     3printOut = dump 
  • orange/orngTest.py

    r6733 r7413  
    1 import orange 
    2 from orngMisc import demangleExamples, getobjectname, printVerbose 
    3 import exceptions, cPickle, os, os.path 
    4  
    5 #### Some private stuff 
    6  
    7 def encodePP(pps): 
    8     pps="" 
    9     for pp in pps: 
    10         objname = getobjectname(pp[1], "") 
    11         if len(objname): 
    12             pps+="_"+objname 
    13         else: 
    14             return "*" 
    15     return pps 
    16  
    17 #### Data structures 
    18  
    19 class TestedExample: 
    20     def __init__(self, iterationNumber=None, actualClass=None, n=0, weight=1.0): 
    21         self.classes = [None]*n 
    22         self.probabilities = [None]*n 
    23         self.iterationNumber = iterationNumber 
    24         self.actualClass= actualClass 
    25         self.weight = weight 
    26      
    27     def addResult(self, aclass, aprob): 
    28         if type(aclass.value)==float: 
    29             self.classes.append(float(aclass)) 
    30             self.probabilities.append(aprob) 
    31         else: 
    32             self.classes.append(int(aclass)) 
    33             self.probabilities.append(list(aprob)) 
    34  
    35     def setResult(self, i, aclass, aprob): 
    36         if type(aclass.value)==float: 
    37             self.classes[i] = float(aclass) 
    38             self.probabilities[i] = aprob 
    39         else: 
    40             self.classes[i] = int(aclass) 
    41             self.probabilities[i] = list(aprob) 
    42  
    43 class ExperimentResults(object): 
    44     def __init__(self, iterations, classifierNames, classValues, weights, baseClass=-1, **argkw): 
    45         self.classValues = classValues 
    46         self.classifierNames = classifierNames 
    47         self.numberOfIterations = iterations 
    48         self.numberOfLearners = len(classifierNames) 
    49         self.results = [] 
    50         self.classifiers = [] 
    51         self.loaded = None 
    52         self.baseClass = baseClass 
    53         self.weights = weights 
    54         self.__dict__.update(argkw) 
    55  
    56     def loadFromFiles(self, learners, filename): 
    57         self.loaded = [] 
    58        
    59         for i in range(len(learners)): 
    60             f = None 
    61             try: 
    62                 f = open(".\\cache\\"+filename % getobjectname(learners[i], "*"), "rb") 
    63                 d = cPickle.load(f) 
    64                 for ex in range(len(self.results)): 
    65                     tre = self.results[ex] 
    66                     if (tre.actualClass, tre.iterationNumber) != d[ex][0]: 
    67                         raise SystemError, "mismatching example tables or sampling" 
    68                     self.results[ex].setResult(i, d[ex][1][0], d[ex][1][1]) 
    69                 self.loaded.append(1) 
    70             except exceptions.Exception: 
    71                 self.loaded.append(0) 
    72             if f: 
    73                 f.close() 
    74                  
    75         return not 0 in self.loaded                 
    76                  
    77     def saveToFiles(self, learners, filename): 
    78         for i in range(len(learners)): 
    79             if self.loaded[i]: 
    80                 continue 
    81              
    82             fname=".\\cache\\"+filename % getobjectname(learners[i], "*") 
    83             if not "*" in fname: 
    84                 if not os.path.isdir("cache"): 
    85                     os.mkdir("cache") 
    86                 f=open(fname, "wb") 
    87                 pickler=cPickle.Pickler(f, 1) 
    88                 pickler.dump([(  (x.actualClass, x.iterationNumber), (x.classes[i], x.probabilities[i])  ) for x in self.results]) 
    89                 f.close() 
    90  
    91     def remove(self, index): 
    92         """remove one learner from evaluation results""" 
    93         for r in self.results: 
    94             del r.classes[index] 
    95             del r.probabilities[index] 
    96         del self.classifierNames[index] 
    97         self.numberOfLearners -= 1 
    98  
    99     def add(self, results, index, replace=-1): 
    100         """add evaluation results (for one learner)""" 
    101         if len(self.results)<>len(results.results): 
    102             raise SystemError, "mismatch in number of test cases" 
    103         if self.numberOfIterations<>results.numberOfIterations: 
    104             raise SystemError, "mismatch in number of iterations (%d<>%d)" % \ 
    105                   (self.numberOfIterations, results.numberOfIterations) 
    106         if len(self.classifiers) and len(results.classifiers)==0: 
    107             raise SystemError, "no classifiers in results" 
    108  
    109         if replace < 0 or replace >= self.numberOfLearners: # results for new learner 
    110             self.classifierNames.append(results.classifierNames[index]) 
    111             self.numberOfLearners += 1 
    112             for i,r in enumerate(self.results): 
    113                 r.classes.append(results.results[i].classes[index]) 
    114                 r.probabilities.append(results.results[i].probabilities[index]) 
    115             if len(self.classifiers): 
    116                 for i in range(self.numberOfIterations): 
    117                     self.classifiers[i].append(results.classifiers[i][index]) 
    118         else: # replace results of existing learner 
    119             self.classifierNames[replace] = results.classifierNames[index] 
    120             for i,r in enumerate(self.results): 
    121                 r.classes[replace] = results.results[i].classes[index] 
    122                 r.probabilities[replace] = results.results[i].probabilities[index] 
    123             if len(self.classifiers): 
    124                 for i in range(self.numberOfIterations): 
    125                     self.classifiers[replace] = results.classifiers[i][index] 
    126  
    127 #### Experimental procedures 
    128  
    129 def leaveOneOut(learners, examples, pps=[], indicesrandseed="*", **argkw): 
    130     """leave-one-out evaluation of learners on a data set""" 
    131     (examples, weight) = demangleExamples(examples) 
    132     return testWithIndices(learners, examples, range(len(examples)), indicesrandseed, pps, **argkw) 
    133     # return testWithIndices(learners, examples, range(len(examples)), pps=pps, argkw) 
    134  
    135 # apply(testWithIndices, (learners, (examples, weight), indices, indicesrandseed, pps), argkw) 
    136  
    137  
    138 def proportionTest(learners, examples, learnProp, times=10, 
    139                    strat=orange.MakeRandomIndices.StratifiedIfPossible, 
    140                    pps=[], callback=None, **argkw): 
    141     """train-and-test evaluation (train on a subset, test on remaing examples)""" 
    142     # randomGenerator is set either to what users provided or to orange.RandomGenerator(0) 
    143     # If we left it None or if we set MakeRandomIndices2.randseed, it would give same indices each time it's called 
    144     randomGenerator = argkw.get("indicesrandseed", 0) or argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
    145     pick = orange.MakeRandomIndices2(stratified = strat, p0 = learnProp, randomGenerator = randomGenerator) 
    146      
    147     examples, weight = demangleExamples(examples) 
    148     classVar = examples.domain.classVar 
    149     if classVar.varType == orange.VarTypes.Discrete: 
    150         values = list(classVar.values) 
    151         baseValue = classVar.baseValue 
    152     else: 
    153         baseValue = values = None 
    154     testResults = ExperimentResults(times, [l.name for l in learners], values, weight!=0, baseValue) 
    155  
    156     for time in range(times): 
    157         indices = pick(examples) 
    158         learnset = examples.selectref(indices, 0) 
    159         testset = examples.selectref(indices, 1) 
    160         learnAndTestOnTestData(learners, (learnset, weight), (testset, weight), testResults, time, pps, **argkw) 
    161         if callback: callback() 
    162     return testResults 
    163  
    164 def crossValidation(learners, examples, folds=10, 
    165                     strat=orange.MakeRandomIndices.StratifiedIfPossible, 
    166                     pps=[], indicesrandseed="*", **argkw): 
    167     """cross-validation evaluation of learners""" 
    168     (examples, weight) = demangleExamples(examples) 
    169     if indicesrandseed!="*": 
    170         indices = orange.MakeRandomIndicesCV(examples, folds, randseed=indicesrandseed, stratified = strat) 
    171     else: 
    172         randomGenerator = argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
    173         indices = orange.MakeRandomIndicesCV(examples, folds, stratified = strat, randomGenerator = randomGenerator) 
    174     return testWithIndices(learners, (examples, weight), indices, indicesrandseed, pps, **argkw) 
    175  
    176  
    177 def learningCurveN(learners, examples, folds=10, 
    178                    strat=orange.MakeRandomIndices.StratifiedIfPossible, 
    179                    proportions=orange.frange(0.1), pps=[], **argkw): 
    180     """construct a learning curve for learners""" 
    181     seed = argkw.get("indicesrandseed", -1) or argkw.get("randseed", -1) 
    182     if seed: 
    183         randomGenerator = orange.RandomGenerator(seed) 
    184     else: 
    185         randomGenerator = argkw.get("randomGenerator", orange.RandomGenerator()) 
    186          
    187     if strat: 
    188         cv=orange.MakeRandomIndicesCV(folds = folds, stratified = strat, randomGenerator = randomGenerator) 
    189         pick=orange.MakeRandomIndices2(stratified = strat, randomGenerator = randomGenerator) 
    190     else: 
    191         cv=orange.RandomIndicesCV(folds = folds, stratified = strat, randomGenerator = randomGenerator) 
    192         pick=orange.RandomIndices2(stratified = strat, randomGenerator = randomGenerator) 
    193     return apply(learningCurve, (learners, examples, cv, pick, proportions, pps), argkw) 
    194  
    195  
    196 def learningCurve(learners, examples, cv=None, pick=None, proportions=orange.frange(0.1), pps=[], **argkw): 
    197     verb = argkw.get("verbose", 0) 
    198     cache = argkw.get("cache", 0) 
    199     callback = argkw.get("callback", 0) 
    200  
    201     for pp in pps: 
    202         if pp[0]!="L": 
    203             raise SystemError, "cannot preprocess testing examples" 
    204  
    205     if not cv or not pick:     
    206         seed = argkw.get("indicesrandseed", -1) or argkw.get("randseed", -1) 
    207         if seed: 
    208             randomGenerator = orange.RandomGenerator(seed) 
    209         else: 
    210             randomGenerator = argkw.get("randomGenerator", orange.RandomGenerator()) 
    211         if not cv: 
    212             cv = orange.MakeRandomIndicesCV(folds=10, stratified=orange.MakeRandomIndices.StratifiedIfPossible, randomGenerator = randomGenerator) 
    213         if not pick: 
    214             pick = orange.MakeRandomIndices2(stratified=orange.MakeRandomIndices.StratifiedIfPossible, randomGenerator = randomGenerator) 
    215  
    216     examples, weight = demangleExamples(examples) 
    217     folds = cv(examples) 
    218     ccsum = hex(examples.checksum())[2:] 
    219     ppsp = encodePP(pps) 
    220     nLrn = len(learners) 
    221  
    222     allResults=[] 
    223     for p in proportions: 
    224         printVerbose("Proportion: %5.3f" % p, verb) 
    225  
    226         if (cv.randseed<0) or (pick.randseed<0): 
    227             cache = 0 
    228         else: 
    229             fnstr = "{learningCurve}_%s_%s_%s_%s%s-%s" % ("%s", p, cv.randseed, pick.randseed, ppsp, ccsum) 
    230             if "*" in fnstr: 
    231                 cache = 0 
    232  
    233         conv = examples.domain.classVar.varType == orange.VarTypes.Discrete and int or float 
    234         testResults = ExperimentResults(cv.folds, [l.name for l in learners], examples.domain.classVar.values.native(), weight!=0, examples.domain.classVar.baseValue) 
    235         testResults.results = [TestedExample(folds[i], conv(examples[i].getclass()), nLrn, examples[i].getweight(weight)) 
    236                                for i in range(len(examples))] 
    237  
    238         if cache and testResults.loadFromFiles(learners, fnstr): 
    239             printVerbose("  loaded from cache", verb) 
    240         else: 
    241             for fold in range(cv.folds): 
    242                 printVerbose("  fold %d" % fold, verb) 
    243                  
    244                 # learning 
    245                 learnset = examples.selectref(folds, fold, negate=1) 
    246                 learnset = learnset.selectref(pick(learnset, p0=p), 0) 
    247                 if not len(learnset): 
    248                     continue 
    249                  
    250                 for pp in pps: 
    251                     learnset = pp[1](learnset) 
    252  
    253                 classifiers = [None]*nLrn 
    254                 for i in range(nLrn): 
    255                     if not cache or not testResults.loaded[i]: 
    256                         classifiers[i] = learners[i](learnset, weight) 
    257  
    258                 # testing 
    259                 for i in range(len(examples)): 
    260                     if (folds[i]==fold): 
    261                         # This is to prevent cheating: 
    262                         ex = orange.Example(examples[i]) 
    263                         ex.setclass("?") 
    264                         for cl in range(nLrn): 
    265                             if not cache or not testResults.loaded[cl]: 
    266                                 cls, pro = classifiers[cl](ex, orange.GetBoth) 
    267                                 testResults.results[i].setResult(cl, cls, pro) 
    268                 if callback: callback() 
    269             if cache: 
    270                 testResults.saveToFiles(learners, fnstr) 
    271  
    272         allResults.append(testResults) 
    273          
    274     return allResults 
    275  
    276  
    277 def learningCurveWithTestData(learners, learnset, testset, times=10, 
    278                               proportions=orange.frange(0.1), 
    279                               strat=orange.MakeRandomIndices.StratifiedIfPossible, pps=[], **argkw): 
    280     verb = argkw.get("verbose", 0) 
    281  
    282     learnset, learnweight = demangleExamples(learnset) 
    283     testweight = demangleExamples(testset)[1] 
    284      
    285     randomGenerator = argkw.get("indicesrandseed", 0) or argkw.get("randseed", 0) or argkw.get("randomGenerator", 0) 
    286     pick = orange.MakeRandomIndices2(stratified = strat, randomGenerator = randomGenerator) 
    287     allResults=[] 
    288     for p in proportions: 
    289         printVerbose("Proportion: %5.3f" % p, verb) 
    290         testResults = ExperimentResults(times, [l.name for l in learners], 
    291                                         testset.domain.classVar.values.native(), 
    292                                         testweight!=0, testset.domain.classVar.baseValue) 
    293         testResults.results = [] 
    294          
    295         for t in range(times): 
    296             printVerbose("  repetition %d" % t, verb) 
    297             learnAndTestOnTestData(learners, (learnset.selectref(pick(learnset, p), 0), learnweight), 
    298                                    testset, testResults, t) 
    299  
    300         allResults.append(testResults) 
    301          
    302     return allResults 
    303  
    304     
    305 def testWithIndices(learners, examples, indices, indicesrandseed="*", pps=[], callback=None, **argkw): 
    306     verb = argkw.get("verbose", 0) 
    307     cache = argkw.get("cache", 0) 
    308     storeclassifiers = argkw.get("storeclassifiers", 0) or argkw.get("storeClassifiers", 0) 
    309     cache = cache and not storeclassifiers 
    310  
    311     examples, weight = demangleExamples(examples) 
    312     nLrn = len(learners) 
    313  
    314     if not examples: 
    315         raise SystemError, "Test data set with no examples" 
    316     if not examples.domain.classVar: 
    317         raise "Test data set without class attribute" 
    318      
    319 ##    for pp in pps: 
    320 ##        if pp[0]!="L": 
    321 ##            raise SystemError, "cannot preprocess testing examples" 
    322  
    323     nIterations = max(indices)+1 
    324     if examples.domain.classVar.varType == orange.VarTypes.Discrete: 
    325         values = list(examples.domain.classVar.values) 
    326         basevalue = examples.domain.classVar.baseValue 
    327     else: 
    328         basevalue = values = None 
    329  
    330     conv = examples.domain.classVar.varType == orange.VarTypes.Discrete and int or float         
    331     testResults = ExperimentResults(nIterations, [getobjectname(l) for l in learners], values, weight!=0, basevalue) 
    332     testResults.results = [TestedExample(indices[i], conv(examples[i].getclass()), nLrn, examples[i].getweight(weight)) 
    333                            for i in range(len(examples))] 
    334  
    335     if argkw.get("storeExamples", 0): 
    336         testResults.examples = examples 
    337          
    338     ccsum = hex(examples.checksum())[2:] 
    339     ppsp = encodePP(pps) 
    340     fnstr = "{TestWithIndices}_%s_%s%s-%s" % ("%s", indicesrandseed, ppsp, ccsum) 
    341     if "*" in fnstr: 
    342         cache = 0 
    343  
    344     if cache and testResults.loadFromFiles(learners, fnstr): 
    345         printVerbose("  loaded from cache", verb) 
    346     else: 
    347         for fold in range(nIterations): 
    348             # learning 
    349             learnset = examples.selectref(indices, fold, negate=1) 
    350             if not len(learnset): 
    351                 continue 
    352             testset = examples.selectref(indices, fold, negate=0) 
    353             if not len(testset): 
    354                 continue 
    355              
    356             for pp in pps: 
    357                 if pp[0]=="B": 
    358                     learnset = pp[1](learnset) 
    359                     testset = pp[1](testset) 
    360  
    361             for pp in pps: 
    362                 if pp[0]=="L": 
    363                     learnset = pp[1](learnset) 
    364                 elif pp[0]=="T": 
    365                     testset = pp[1](testset) 
    366                 elif pp[0]=="LT": 
    367                     (learnset, testset) = pp[1](learnset, testset) 
    368  
    369             if not learnset: 
    370                 raise SystemError, "no training examples after preprocessing" 
    371  
    372             if not testset: 
    373                 raise SystemError, "no test examples after preprocessing" 
    374  
    375             classifiers = [None]*nLrn 
    376             for i in range(nLrn): 
    377                 if not cache or not testResults.loaded[i]: 
    378                     classifiers[i] = learners[i](learnset, weight) 
    379             if storeclassifiers:     
    380                 testResults.classifiers.append(classifiers) 
    381  
    382             # testing 
    383             tcn = 0 
    384             for i in range(len(examples)): 
    385                 if (indices[i]==fold): 
    386                     # This is to prevent cheating: 
    387                     ex = orange.Example(testset[tcn]) 
    388                     ex.setclass("?") 
    389                     tcn += 1 
    390                     for cl in range(nLrn): 
    391                         if not cache or not testResults.loaded[cl]: 
    392                             cr = classifiers[cl](ex, orange.GetBoth)                                       
    393                             if cr[0].isSpecial(): 
    394                                 raise "Classifier %s returned unknown value" % (classifiers[cl].name or ("#%i" % cl)) 
    395                             testResults.results[i].setResult(cl, cr[0], cr[1]) 
    396             if callback: 
    397                 callback() 
    398         if cache: 
    399             testResults.saveToFiles(learners, fnstr) 
    400          
    401     return testResults 
    402  
    403  
    404 def learnAndTestOnTestData(learners, learnset, testset, testResults=None, iterationNumber=0, pps=[], callback=None, **argkw): 
    405     storeclassifiers = argkw.get("storeclassifiers", 0) or argkw.get("storeClassifiers", 0) 
    406     storeExamples = argkw.get("storeExamples", 0) 
    407  
    408     learnset, learnweight = demangleExamples(learnset) 
    409     testset, testweight = demangleExamples(testset) 
    410     storeclassifiers = argkw.get("storeclassifiers", 0) or argkw.get("storeClassifiers", 0) 
    411      
    412     for pp in pps: 
    413         if pp[0]=="B": 
    414             learnset = pp[1](learnset) 
    415             testset = pp[1](testset) 
    416  
    417     for pp in pps: 
    418         if pp[0]=="L": 
    419             learnset = pp[1](learnset) 
    420         elif pp[0]=="T": 
    421             testset = pp[1](testset) 
    422         elif pp[0]=="LT": 
    423             learnset, testset = pp[1](learnset, testset) 
    424              
    425     classifiers = [] 
    426     for learner in learners: 
    427         classifiers.append(learner(learnset, learnweight)) 
    428         if callback: 
    429             callback() 
    430     classifiers = [learner(learnset, learnweight) for learner in learners] 
    431     for i in range(len(learners)): classifiers[i].name = getattr(learners[i], 'name', 'noname') 
    432     testResults = testOnData(classifiers, (testset, testweight), testResults, iterationNumber, storeExamples) 
    433     if storeclassifiers: 
    434         testResults.classifiers.append(classifiers) 
    435     return testResults 
    436  
    437  
    438 def learnAndTestOnLearnData(learners, learnset, testResults=None, iterationNumber=0, pps=[], callback=None, **argkw): 
    439     storeclassifiers = argkw.get("storeclassifiers", 0) or argkw.get("storeClassifiers", 0) 
    440     storeExamples = argkw.get("storeExamples", 0) 
    441  
    442     learnset, learnweight = demangleExamples(learnset) 
    443  
    444     hasLorT = 0     
    445     for pp in pps: 
    446         if pp[0]=="B": 
    447             learnset = pp[1](learnset) 
    448         else: 
    449             hasLorT = 1 
    450  
    451     if hasLorT: 
    452         testset = orange.ExampleTable(learnset) 
    453         for pp in pps: 
    454             if pp[0]=="L": 
    455                 learnset = pp[1](learnset) 
    456             elif pp[0]=="T": 
    457                 testset = pp[1](testset) 
    458             elif pp[0]=="LT": 
    459                 learnset, testset = pp[1](learnset, testset) 
    460     else: 
    461         testset = learnset     
    462  
    463     classifiers = [] 
    464     for learner in learners: 
    465         classifiers.append(learner(learnset, learnweight)) 
    466         if callback: 
    467             callback() 
    468     for i in range(len(learners)): classifiers[i].name = getattr(learners[i], "name", "noname") 
    469     testResults = testOnData(classifiers, (testset, learnweight), testResults, iterationNumber, storeExamples) 
    470     if storeclassifiers: 
    471         testResults.classifiers.append(classifiers) 
    472     return testResults 
    473  
    474  
    475 def testOnData(classifiers, testset, testResults=None, iterationNumber=0, storeExamples = False, **argkw): 
    476     testset, testweight = demangleExamples(testset) 
    477  
    478     if not testResults: 
    479         classVar = testset.domain.classVar 
    480         if testset.domain.classVar.varType == orange.VarTypes.Discrete: 
    481             values = classVar.values.native() 
    482             baseValue = classVar.baseValue 
    483         else: 
    484             values = None 
    485             baseValue = -1 
    486         testResults=ExperimentResults(1, [l.name for l in classifiers], values, testweight!=0, baseValue) 
    487  
    488     examples = getattr(testResults, "examples", False) 
    489     if examples and len(examples): 
    490         # We must not modify an example table we do not own, so we clone it the 
    491         # first time we have to add to it 
    492         if not getattr(testResults, "examplesCloned", False): 
    493             testResults.examples = orange.ExampleTable(testResults.examples) 
    494             testResults.examplesCloned = True 
    495         testResults.examples.extend(testset) 
    496     else: 
    497         # We do not clone at the first iteration - cloning might never be needed at all... 
    498         testResults.examples = testset 
    499      
    500     conv = testset.domain.classVar.varType == orange.VarTypes.Discrete and int or float 
    501     for ex in testset: 
    502         te = TestedExample(iterationNumber, conv(ex.getclass()), 0, ex.getweight(testweight)) 
    503  
    504         for classifier in classifiers: 
    505             # This is to prevent cheating: 
    506             ex2 = orange.Example(ex) 
    507             ex2.setclass("?") 
    508             cr = classifier(ex2, orange.GetBoth) 
    509             te.addResult(cr[0], cr[1]) 
    510         testResults.results.append(te) 
    511          
    512     return testResults 
     1from Orange.evaluation.testing import * 
Note: See TracChangeset for help on using the changeset viewer.