source: orange/Orange/multilabel/multiknn.py @ 10417:096d1f75db02

Revision 10417:096d1f75db02, 1.9 KB checked in by janezd <janez.demsar@…>, 2 years ago (diff)

Reorganized documentation about multilabel learning

Line 
1"""
2.. index:: MultikNN Learner
3   
4.. index::
5   single: multilabel;  MultikNN Learner
6
7***************************************
8MultikNN Learner
9***************************************
10
11MultikNN Classification is the base class of kNN method based multi-label
12classification.
13
14.. index:: MultikNN Learner
15.. autoclass:: Orange.multilabel.MultikNNLearner
16   :members:
17   :show-inheritance:
18 
19   :param instances: a table of instances.
20   :type instances: :class:`Orange.data.Table`
21
22.. index:: MultikNN Classifier
23.. autoclass:: Orange.multilabel.MultikNNClassifier
24   :members:
25   :show-inheritance:
26   
27"""
28import random
29
30import Orange
31import multibase as _multibase
32
33class MultikNNLearner(_multibase.MultiLabelLearner):
34    """
35    Class implementing the MultikNN (Multi-Label k Nearest Neighbours) algorithm.
36   
37    .. attribute:: k
38   
39        Number of neighbors. The default value is 1
40   
41    .. attribute:: num_labels
42   
43        Number of labels
44   
45    .. attribute:: label_indices
46   
47        The indices of labels in the domain
48   
49    .. attribute:: knn
50       
51        :class:`Orange.classification.knn.FindNearest` for nearest neighbor search
52   
53    """
54    def __new__(cls, k=1, **argkw):
55        """
56        Constructor for MultikNNLearner
57               
58        :param k: number of nearest neighbors used in classification
59        :type k: int
60       
61        :rtype: :class:`MultikNNLearner`
62        """
63       
64        self = _multibase.MultiLabelLearner.__new__(cls, **argkw)
65        self.k = k
66        return self
67   
68    def _build_knn(self, instances):
69        nnc = Orange.classification.knn.FindNearestConstructor()
70        nnc.distanceConstructor = Orange.distance.Euclidean()
71       
72        weight_id = Orange.feature.Descriptor.new_meta_id()
73        self.knn = nnc(instances, 0, weight_id)
74        self.weight_id = weight_id
75
76class MultikNNClassifier(_multibase.MultiLabelClassifier):
77    pass
78       
Note: See TracBrowser for help on using the repository browser.