source: orange/docs/reference/rst/Orange.classification.classfromvar.rst @ 10373:7013ad52894e

Revision 10373:7013ad52894e, 3.7 KB checked in by janezd <janez.demsar@…>, 2 years ago (diff)

Improved, simplified and updated documentation about classification.classfromvar

Line 
1.. index: classification from variable
2.. index:
3   single: classification; classification from variable
4
5************************
6Classifier from variable
7************************
8
9:obj:`~Orange.classification.ClassifierFromVar` and
10:obj:`~Orange.classification.ClassifierFromVarFD` are helper
11classifiers used to compute variable's values from another variables. They are used, for instance, in discretization of continuous variables.
12
13:obj:`~Orange.classification.ClassifierFromVarFD` retrieves the
14feature value based on its position in the domain and
15:obj:`~Orange.classification.ClassifierFromVar` retrieves the feature
16with the given descriptor.
17
18Both classifiers can be given a function to transform the value. In
19discretization, for instance, the transformer computes the
20corresponding discrete interval for a continuous value of the original
21variable.
22
23
24.. class:: ClassifierFromVar(which_var[, transformer])
25   
26    Return the value of variable :obj:`which_var`; transform it by the
27    :obj:`transformer`, if it is given.
28 
29    .. attribute:: which_var
30
31        The descriptor of the feature whose value is returned.
32
33    .. attribute:: transformer       
34
35        The transformer for the value. It should be a class derived
36        from :obj:`Orange.data.utils.TransformValue` or a function
37        written in Python.
38
39    .. attribute:: transform_unknowns
40
41        Defines the treatment of missing values.
42
43    .. attribute:: distribution_for_unknown
44
45        The distribution that is returned when the `which_var`'s value
46        is undefined and :obj:`transform_unknowns` is ``False``.
47
48    .. method:: __call__(inst[, result_type])
49
50        Return ``transformer(instance[which_var])``. The value of
51        :obj:`which_var` can be either an ordinary variable, a meta
52        variable or a variable which is not defined for the instance
53        but its descriptor has a
54        :obj:`~Orange.feature.Descriptor.get_value_from` that can be
55        used to compute the value.
56
57        If the feature is not found or its value is missing, the
58        missing value is passed to the transformer if
59        :obj:`transform_unknowns` is ``True``. Otherwise,
60        :obj:`distribution_for_unknown` is returned.
61
62The following example demonstrates the use of the class on the Monk 1
63dataset. It construct a new variable `e1` that has a value of `1`, when
64`e` is `1`, and `not 1` otherwise.
65
66.. literalinclude:: code/classifier-from-var-example.py
67    :lines: 1-19
68
69
70
71.. class:: ClassifierFromVarFD
72
73    A class similar to
74    :obj:`~Orange.classification.ClassifierFromVar` except that the
75    variable is given by its index in the domain. The index can also
76    be negative to denote a meta attribute.
77
78    The only practical difference between the two classes is that this
79    does not compute the value of the variable from other variables
80    through the descriptor's
81    :obj:`Orange.feature.Descriptor.get_value_from`.
82
83    .. attribute:: domain (inherited from ClassifierFromVarFD)
84   
85        The domain to which the :obj:`position` applies.
86
87    .. attribute:: position
88
89        The position of the attribute in the domain or its meta-id.
90
91    .. attribute:: transformer       
92
93        The transformer for the value. It should be a class derived
94        from :obj:`Orange.data.utils.TransformValue` or a function
95        written in Python.
96
97    .. attribute:: transform_unknowns
98
99        Defines the treatment of missing values.
100
101    .. attribute:: distribution_for_unknown
102
103        The distribution that is returned when the `which_var`'s value
104        is undefined and :obj:`transform_unknowns` is ``False``.
105
106    The use of this class is similar to that of
107    :obj:`~Orange.classification.ClassifierFromVar`.
108
109    .. literalinclude:: code/classifier-from-var-example.py
110        :lines: 21-25
Note: See TracBrowser for help on using the repository browser.