Changeset 9460:9b3b86bc7702 in orange


Ignore:
Timestamp:
07/21/11 18:35:49 (3 years ago)
Author:
wencanluo <wencanluo@…>
Branch:
default
Convert:
a29f78a38e3ae909171ba3c2cf4ac380904403e6
Message:

Add LabelPowerset method for multi-label classification, see Orange/multilabel/lp.py

Location:
orange
Files:
2 added
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/__init__.py

    r9459 r9460  
    6464_import("multilabel.multibase") 
    6565_import("multilabel.br") 
    66 _import("multilabel.powerset") 
     66_import("multilabel.lp") 
    6767 
    6868_import("associate") 
  • orange/Orange/multilabel/__init__.py

    r9459 r9460  
    55from br import BinaryRelevanceClassifier 
    66 
    7 from powerset import PowersetLearner 
    8 from powerset import PowersetClassifier 
     7from lp import LabelPowersetLearner 
     8from lp import LabelPowersetClassifier 
  • orange/Orange/multilabel/br.py

    r9456 r9460  
    5151 
    5252.. literalinclude:: code/mlc-classify.py 
    53    :lines: 1- 
     53   :lines: 1-13 
    5454 
    5555.. _mlc-classify.py: code/mlc-br-example.py 
     
    8888            self.__dict__[k] = kwds[k] 
    8989 
    90         num_labels = label.get_num_labels(instances); 
    91         label_indices = label.get_label_indices(instances); 
     90        num_labels = label.get_num_labels(instances) 
     91        label_indices = label.get_label_indices(instances) 
    9292         
    9393        classifiers = [] 
  • orange/Orange/multilabel/label.py

    r9447 r9460  
    6161            id = id + 1 
    6262    return newdomain 
    63              
     63     
     64def get_label_bitstream(data,example): 
     65    """ get the labels in terms of a string of 0 and 1 """ 
     66    if not isinstance(data, Orange.data.Table): 
     67        raise TypeError('data must be of type \'Orange.data.Table\'') 
     68     
     69    value = '' 
     70    for i, var in enumerate(data.domain.variables): 
     71        if var.attributes.has_key('label'): 
     72            value += example[var].value 
     73    return value       
  • orange/Orange/multilabel/multibase.py

    r9453 r9460  
    1515     
    1616    def __init__(self, **argkw): 
     17        self.multi_flag = 1 
    1718        self.__dict__.update(argkw) 
    1819         
    1920class MultiLabelClassifier(Orange.classification.Classifier): 
    2021    def __init__(self, **argkw): 
     22        self.multi_flag = 1 
    2123        self.__dict__.update(argkw) 
    2224      
  • orange/doc/Orange/hiearchy.txt

    r9459 r9460  
    3737      tuning 
    3838   multilabel 
    39       br; powerset 
     39      br; lp 
  • orange/doc/Orange/rst/Orange.multilabel.rst

    r9459 r9460  
    99 
    1010   Orange.multilabel.br 
    11    Orange.multilabel.powerset 
     11   Orange.multilabel.lp 
  • orange/doc/Orange/rst/code/mlc-classify.py

    r9459 r9460  
    1313    #prints [<orange.Value 'Religion'='1'>, <orange.Value 'SCience'='1'>] <0.000, 1.000, 1.000, 0.000> 
    1414     
    15 powerset_cliassifer = Orange.multilabel.PowersetLearner(data) 
     15powerset_cliassifer = Orange.multilabel.LabelPowersetLearner(data) 
    1616for e in data: 
    1717    c,p = powerset_cliassifer(e,Orange.classification.Classifier.GetBoth) 
    1818    print c,p 
    19  
     19    #prints [<orange.Value 'Sports'='1'>, <orange.Value 'Politics'='1'>] <1.000, 0.000, 0.000, 1.000> 
     20    #prints [<orange.Value 'SCience'='1'>, <orange.Value 'Politics'='1'>] <0.000, 0.000, 1.000, 1.000> 
     21    #prints [<orange.Value 'Sports'='1'>] <1.000, 0.000, 0.000, 0.000> 
     22    #prints [<orange.Value 'Religion'='1'>, <orange.Value 'SCience'='1'>] <0.000, 1.000, 1.000, 0.000> 
  • orange/doc/Orange/rst/code/mlc-label-example.py

    r9447 r9460  
    77for e in data:  
    88    print label.get_labels(data,e) 
     9#print [<orange.Value 'Sports'='1'>, <orange.Value 'Religion'='0'>, <orange.Value 'Science'='0'>, <orange.Value 'Politics'='1'>] 
     10#print [<orange.Value 'Sports'='0'>, <orange.Value 'Religion'='0'>, <orange.Value 'Science'='1'>, <orange.Value 'Politics'='1'>] 
     11#print [<orange.Value 'Sports'='1'>, <orange.Value 'Religion'='0'>, <orange.Value 'Science'='0'>, <orange.Value 'Politics'='0'>] 
     12#print [<orange.Value 'Sports'='0'>, <orange.Value 'Religion'='1'>, <orange.Value 'Science'='1'>, <orange.Value 'Politics'='0'>] 
     13 
     14#test get_lable_bitstream 
     15for e in data: 
     16    print label.get_label_bitstream(data,e) 
     17print 
     18#1001 
     19#0011 
     20#1000 
     21#0110 
    922 
    1023#test getNumLabels 
    1124print label.get_num_labels(data) 
     25#print 4 
    1226 
    1327#test getlabelIndices 
     
    1529    print data.domain[id].name, 
    1630print 
     31# print Sports Religion Science Politics 
    1732 
    1833#test removeIndices 
    1934sub_domain = label.remove_indices(data,[2,3,4]) 
    2035print sub_domain 
     36#print [EnumVariable 'Feature', EnumVariable 'Sports'] 
    2137 
    2238sub_domain = Orange.data.Domain(sub_domain,sub_domain[0]) 
    2339print sub_domain.classVar 
     40#print EnumVariable 'Feature' 
     41 
    2442data2 = data.translate(sub_domain) 
    2543 
    2644for e in data2: 
    2745    print e 
     46#['1', '1', '1'] 
     47#['2', '0', '2'] 
     48#['3', '1', '3'] 
     49#['4', '0', '4'] 
Note: See TracChangeset for help on using the changeset viewer.