Changeset 9476:99e5d6d30847 in orange


Ignore:
Timestamp:
08/12/11 19:14:48 (3 years ago)
Author:
wencanluo <wencanluo@…>
Branch:
default
Convert:
90fe116dd4cf222e342636b0adcf66d85fb6e939
Message:

Fix debugs in OWLP, OWMLkNN and so on

Location:
orange
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/multilabel/label.py

    r9466 r9476  
    22 
    33def get_labels(data,example): 
    4     """ get the label list in the example, using 0,1 to indicate whether the example is belong to the label """ 
     4    """ get the list of labels of the example, using 0,1 to indicate whether the example is belong to this label """ 
    55    if not isinstance(data, Orange.data.Table): 
    66        raise TypeError('data must be of type \'Orange.data.Table\'') 
     
    1717 
    1818def is_multilabel(data): 
    19     """ Judge whether the data is multi-label, if so, return 1, else return 0""" 
     19    """ Judge whether the data is multi-label data; if so, return 1, else return 0""" 
    2020    if not isinstance(data, Orange.data.Table): 
    2121        raise TypeError('data must be of type \'Orange.data.Table\'') 
     
    2525 
    2626def get_label_indices(data): 
    27     """ get an array containing the indexes of the label attributes within the object of the training data in increasing order. """ 
     27    """ get the index array of the label in the attributes in an increasing order. """ 
    2828    if not isinstance(data, Orange.data.Table): 
    2929        raise TypeError('data must be of type \'Orange.data.Table\'') 
     
    3333 
    3434def get_label_names(data): 
    35     """ get the list of all label names """ 
     35    """ get a list of label names """ 
    3636    if not isinstance(data, Orange.data.Table): 
    3737        raise TypeError('data must be of type \'Orange.data.Table\'') 
     
    4040          if var.attributes.has_key('label')] 
    4141 
    42 def remove_indices(data,indicesToRemove): 
    43     """ remove the attributes in the data according to indicesToRemove, (the indices are sorted from small to big) """ 
     42def remove_indices(data,indices_to_remove): 
     43    """ remove the attributes in the data according to indices_to_remove, (the indices are sorted from small to large order) """ 
    4444    if not isinstance(data, Orange.data.Table): 
    4545        raise TypeError('data must be of type \'Orange.data.Table\'') 
     
    5050    id = 0 
    5151    while id < len(domain.variables): 
    52         if index < len(indicesToRemove): 
    53             while id < indicesToRemove[index]: 
     52        if index < len(indices_to_remove): 
     53            while id < indices_to_remove[index]: 
    5454                newdomain.append(domain[id]) 
    5555                id = id + 1   
     
    6161            id = id + 1 
    6262    return newdomain 
     63 
     64def remove_labels(data): 
     65    """ remove the label attributes in the data""" 
     66    domain = data.domain 
     67    newdomain =  [domain[i] for i, var in enumerate(data.domain.variables) 
     68          if var.attributes.has_key('label')] 
     69    new_data = data.translate(newdomain) 
    6370     
    6471def get_label_bitstream(data,example): 
  • orange/Orange/multilabel/lp.py

    r9475 r9476  
    147147    data = Orange.data.Table("emotions.tab") 
    148148 
    149     classifier = Orange.multilabel.LabelPowersetLearner(data,Orange.classification.knn.kNNLearner) 
     149    classifier = Orange.multilabel.LabelPowersetLearner(data) 
    150150    for i in range(10): 
    151151        c,p = classifier(data[i],Orange.classification.Classifier.GetBoth) 
  • orange/OrangeWidgets/Evaluate/OWTestLearners.py

    r9475 r9476  
    342342 
    343343        # computation of results (res, and cm if classification) 
     344        print self.resampling 
    344345        pb = None 
    345346        if self.resampling==0: 
    346347            pb = OWGUI.ProgressBar(self, iterations=self.nFolds) 
    347             res = orngTest.crossValidation(learners, self.data, folds=self.nFolds, 
    348                                            strat=orange.MakeRandomIndices.StratifiedIfPossible, 
    349                                            callback=pb.advance, storeExamples = True) 
     348            #print self.nFolds 
     349            #res = orngTest.crossValidation(learners, self.data, folds=self.nFolds, 
     350            #                               strat=orange.MakeRandomIndices.StratifiedIfPossible, 
     351            #                               callback=pb.advance, storeExamples = True) 
     352            res = orngTest.crossValidation(learners, self.data, folds=self.nFolds) 
     353             
     354            loss = Orange.evaluation.scoring.mlc_hamming_loss(res) 
     355            accuracy = Orange.evaluation.scoring.mlc_accuracy(res) 
     356            precision = Orange.evaluation.scoring.mlc_precision(res) 
     357            recall = Orange.evaluation.scoring.mlc_recall(res) 
     358            print 'loss=', loss 
     359            print 'accuracy=', accuracy 
     360            print 'precision=', precision 
     361            print 'recall=', recall 
    350362            pb.finish() 
    351363        elif self.resampling==1: 
     
    436448            #self.statLayout.setCurrentWidget(self.cbox if self.isclassification() else self.rbox) 
    437449             
    438             print multilabel_flag 
     450            #print multilabel_flag 
    439451            #self.stat = [self.rStatistics, self.cStatistics][self.isclassification()] 
    440452            if multilabel_flag == 1: 
     
    606618    data4 = orange.ExampleTable(r'../../doc/datasets/lenses') 
    607619    data5 = orange.ExampleTable(r'../../doc/datasets/multidata') 
     620    data6 = orange.ExampleTable(r'../../doc/datasets/emotions') 
    608621 
    609622    l1 = orange.MajorityLearner(); l1.name = '1 - Majority' 
     
    620633    l4 = orange.MajorityLearner(); l4.name = "4 - Majority" 
    621634    l5 = Orange.multilabel.BinaryRelevanceLearner(); l1.name = '5 - BR' 
     635     
     636    l6 = Orange.multilabel.LabelPowersetLearner(); 
    622637     
    623638    import orngRegression as r 
     
    661676        ow.setData(data5) 
    662677        ow.setLearner(l5, 1) 
     678    if testcase == 6: #label powerset 
     679        ow.setData(data6) 
     680        ow.setLearner(l6,1) 
    663681    ow.saveSettings() 
  • orange/OrangeWidgets/Multilabel/OWBRkNN.py

    r9473 r9476  
    7474          
    7575    def set_learner(self): 
    76         self.learner = Orange.multilabel.BinaryRelevanceLearner(k = self.k) 
     76        self.learner = Orange.multilabel.BRkNNLearner(k = self.k) 
    7777        if self.preprocessor: 
    7878            self.learner = self.preprocessor.wrapLearner(self.learner) 
  • orange/OrangeWidgets/Multilabel/OWLP.py

    r9473 r9476  
    7474     
    7575    def set_learner(self): 
    76         self.learner = Orange.multilabel.BinaryRelevanceLearner(base_learner = self.base_learner) 
     76        self.learner = Orange.multilabel.LabelPowersetLearner(base_learner = self.base_learner) 
    7777        if self.preprocessor: 
    7878            self.learner = self.preprocessor.wrapLearner(self.learner) 
     
    8989                self.classifier = self.learner(self.data) 
    9090                self.classifier.name = self.name 
     91                for i in range(10): 
     92                    c,p = self.classifier(self.data[i],Orange.classification.Classifier.GetBoth) 
     93                    print c,p 
    9194            except Exception, (errValue): 
    9295                self.classifier = None 
     
    103106    ow=OWLP() 
    104107 
    105     dataset = Orange.data.Table('../../doc/datasets/multidata.tab') 
     108    dataset = Orange.data.Table('../../doc/datasets/emotions.tab') 
    106109    ow.set_data(dataset) 
    107110 
  • orange/OrangeWidgets/Multilabel/OWMLkNN.py

    r9473 r9476  
    7474          
    7575    def set_learner(self): 
    76         self.learner = Orange.multilabel.BinaryRelevanceLearner(k = self.k) 
     76        self.learner = Orange.multilabel.MLkNNLearner(k = self.k) 
    7777        if self.preprocessor: 
    7878            self.learner = self.preprocessor.wrapLearner(self.learner) 
Note: See TracChangeset for help on using the changeset viewer.