Orange Forum • View topic - Multilabel classification

Multilabel classification

A place to ask questions about methods in Orange and how they are used and other general support.

Multilabel classification

Postby MONIC » Mon Jan 09, 2012 17:38

Hi
I'm a new one who start to use Python and Orange for multilabel classification.
I run this code via Python Script in Orange canvas
Code: Select all
import Orange

data = Orange.data.Table('emotions')
learner = Orange.multilabel.BRkNNLearner(k=5)
classifier = learner(data)
print classifier(data[0])

learner = Orange.multilabel.MLkNNLearner(k=5)
classifier = learner(data)
print classifier(data[0])

learner = Orange.multilabel.BinaryRelevanceLearner()
classifier = learner(data)
print classifier(data[0])

learner = Orange.multilabel.LabelPowersetLearner()
classifier = learner(data)
print classifier(data[0])

def test_mlc(data, learners):
    for l in learners:
        c = l(data)
        for e in data[:20]:
            labels, probs = c(e, Orange.classification.Classifier.GetBoth)
            print [val.value for val in labels], "[%s]" % ", ".join("(%.4f, %.4f)" % (p['0'], p['1']) for p in probs)
        print

learners = [Orange.multilabel.BinaryRelevanceLearner(),
            Orange.multilabel.LabelPowersetLearner(),
            Orange.multilabel.MLkNNLearner(k=1),
            Orange.multilabel.MLkNNLearner(k=5),
            Orange.multilabel.BRkNNLearner(k=1),
            Orange.multilabel.BRkNNLearner(k=5),
            Orange.multilabel.BRkNNLearner(k=5,ext='a'),
            Orange.multilabel.BRkNNLearner(k=5,ext='b')
            ]
           
test_mlc(Orange.data.Table("emotions.tab"), learners)


it show errors like this

>>>
Running script:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 8, in <module>
File "C:\Python27\lib\site-packages\orange\Orange\multilabel\brknn.py", line 105, in __call__
if not Orange.multilabel.is_multilabel(instances):
File "C:\Python27\lib\site-packages\orange\Orange\multilabel\__init__.py", line 22, in is_multilabel
if not data.domain.class_vars:
AttributeError: 'orange.Domain' has no attribute 'class_vars'
>>>

what wrong with it?

Re: Multilabel classification

Postby Ales » Wed Jan 11, 2012 10:14

Are you sure you are using the latest version of orange? The example code works for me.

Re: Multilabel classification

Postby MONIC » Mon Jan 16, 2012 14:46

The lastest version is Orange2.5, right?

Re: Multilabel classification

Postby MONIC » Sat Jan 28, 2012 11:55

I have try to use refactoring tool orange2to25.py
but it no change in this file

it still have this error

File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Python27\Lib\site-packages\orange\doc\ofb\mlc-classify3.py", line 2, in <module>
import orange.Domain
ImportError: No module named Domain

:cry: :cry:

Re: Multilabel classification

Postby Ales » Mon Jan 30, 2012 12:38

mlc-classify3 should work as is.There is no need to use the conversion script.


Return to Questions & Support