source: orange/docs/reference/rst/code/mlc-classify.py @ 9823:7f9c3f3c6474

Revision 9823:7f9c3f3c6474, 1.4 KB checked in by lanumek, 2 years ago (diff)

Changed names of data sets (table replaced with data or name of the data set).

Line 
1# This file is badly structured to make it possible to embed parts of it
2# into documentation.
3
4import Orange
5
6emotions = Orange.data.Table('emotions')
7learner = Orange.multilabel.BRkNNLearner(k=5)
8classifier = learner(emotions)
9print classifier(emotions[0])
10
11learner = Orange.multilabel.MLkNNLearner(k=5)
12classifier = learner(emotions)
13print classifier(emotions[0])
14
15learner = Orange.multilabel.BinaryRelevanceLearner()
16classifier = learner(emotions)
17print classifier(emotions[0])
18
19learner = Orange.multilabel.LabelPowersetLearner()
20classifier = learner(emotions)
21print classifier(emotions[0])
22
23def test_mlc(data, learners):
24    for l in learners:
25        c = l(data)
26        for e in data[:20]:
27            labels, probs = c(e, Orange.classification.Classifier.GetBoth)
28            print [val.value for val in labels], "[%s]" % ", ".join("(%.4f, %.4f)" % (p['0'], p['1']) for p in probs)
29        print
30
31learners = [Orange.multilabel.BinaryRelevanceLearner(),
32            Orange.multilabel.LabelPowersetLearner(),
33            Orange.multilabel.MLkNNLearner(k=1),
34            Orange.multilabel.MLkNNLearner(k=5),
35            Orange.multilabel.BRkNNLearner(k=1),
36            Orange.multilabel.BRkNNLearner(k=5),
37            Orange.multilabel.BRkNNLearner(k=5,ext='a'),
38            Orange.multilabel.BRkNNLearner(k=5,ext='b')
39            ]
40           
41test_mlc(Orange.data.Table("emotions.tab"), learners)
Note: See TracBrowser for help on using the repository browser.