source: orange/docs/reference/rst/Orange.classification.classfromvar.rst @ 10376:a5843f9312db

Revision 10376:a5843f9312db, 3.9 KB checked in by janezd <janez.demsar@…>, 2 years ago (diff)

merge

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