source: orange/docs/reference/rst/Orange.classification.classfromvar.rst @ 10361:2c8d6b739b3d

Revision 10361:2c8d6b739b3d, 4.8 KB checked in by Lan Zagar <lan.zagar@…>, 2 years ago (diff)

Corrected some links in classfromvar documentation. But a lot of it should be rewritten.

Line 
1.. index: classification from variable
2.. index:
3   single: classification; classification from variable
4
5************************
6Classifier from variable
7************************
8
9Classifiers from variable are used not to predict class values
10but to compute variable's values from another variables.
11For instance, when a continuous variable is discretized and replaced by
12a discrete variable, an instance of a classifier from variable takes
13care of automatic value computation when needed.
14
15There are two classifiers from variable; the simpler :obj:`ClassifierFromVarFD`
16supposes that example is from some fixed domain and the safer
17:obj:`ClassifierFromVar` does not.
18
19Both classifiers can be given a transformer that can modify the value.
20In discretization, for instance, the transformer is responsible to compute
21a discrete interval for a continuous value of the original variable.
22
23
24ClassifierFromVar
25=================
26
27.. class:: ClassifierFromVar(which_var, transformer)
28   
29    Compute variable's values from variable :obj:`~ClassifierFromVar.which_var`
30    using transformation defined by :obj:`~ClassifierFromVar.transformer`.
31
32    .. attribute:: which_var
33
34        The descriptor of the attribute whose value is to be returned.
35
36    .. attribute:: transformer       
37
38        The transformer for the value. It should be a class derived from
39        :obj:`~Orange.data.utils.TransformValue`, but you can also use a
40        callback function.
41
42    .. attribute:: distribution_for_unknown
43
44        The distribution that is returned when the
45        :obj:`~ClassifierFromVar.which_var`'s value is undefined.
46
47When given an instance, :obj:`ClassifierFromVar` will return
48`transformer(instance[which_var])`.
49Attribute :obj:`~ClassifierFromVar.which_var` can be either an ordinary
50variable, a meta variable or a variable which is not defined for the instance
51but has :obj:`~Orange.feature.Descriptor.get_value_from` that can be used to
52compute the value. If none goes through or if the value found is unknown, a
53Value of subtype Distribution containing
54:obj:`~ClassifierFromVar.distribution_for_unknown` is returned.
55
56The class stores the domain version for the last example and its position in
57the domain. If consecutive examples come from the same domain (which is usually
58the case), :obj:`~Orange.classification.ClassifierFromVar` is just two simple
59ifs slower than :obj:`~Orange.classification.ClassifierFromVarFD`.
60
61As you might have guessed, the crucial component here is the transformer.
62Let us, for sake of demonstration, load a `monks-1` dataset and construct an
63attribute `e1` that will have value "1", when `e` is "1", and "not 1" when `e`
64is different than 1. There are many ways to do it, and that same problem is
65covered in different places in Orange documentation. Although the way presented
66here is not the simplest, it will serve to demonstrate how ClassifierFromVar
67works.
68
69
70.. literalinclude:: code/classifier-from-var-example.py
71    :lines: 1-19
72
73ClassifierFromVarFD
74===================
75
76.. class:: ClassifierFromVarFD
77
78    :obj:`ClassifierFromVarFD` is very similar to :obj:`ClassifierFromVar`
79    except that the variable is not given as a descriptor (like
80    :obj:`~ClassifierFromVar.which_var`) but as an index. The index can be
81    either a position of the variable in the domain or a meta-id. Given that
82    :obj:`ClassifierFromVarFD` is practically no faster than
83    :obj:`ClassifierFromVar` (and can in future even be merged with the
84    latter), you should seldom need to use the class.
85
86    .. attribute:: domain (inherited from :obj:`ClassifierFromVarFD`)
87   
88        The domain on which the classifier operates.
89
90    .. attribute:: position
91
92        The position of the attribute in the domain or its meta-id.
93
94    .. attribute:: transformer
95
96        The transformer for the value.
97
98    .. attribute:: distribution_for_unknown
99
100        The distribution that is returned when the which_var's value is undefined.
101
102When an instance is passed to :obj:`~Orange.classification.ClassifierFromVarFD`,
103it is first checked whether it is from the correct domain; an exception is
104raised if not. If the domain is OK, the corresponding attribute value is
105retrieved, transformed and returned.
106
107:obj:`ClassifierFromVarFD`'s twin brother, :obj:`ClassifierFromVar`, can also
108handle variables that are not in the instances' domain or meta-variables,
109but can be computed therefrom by using their
110:obj:`~Orange.feature.Descriptor.get_value_from`. Since
111:obj:`ClassifierFromVarFD` doesn't store attribute descriptor but only an index,
112such functionality is obviously impossible.
113
114To rewrite the above script to use :obj:`ClassifierFromVarFD`,
115we need to set the domain and the `e`'s index to position
116(equivalent to setting which_var in :obj:`ClassifierFromVar`).
117The initialization of :obj:`ClassifierFromVarFD` thus goes like this:
118
119.. literalinclude:: code/classifier-from-var-example.py
120    :lines: 21-25
Note: See TracBrowser for help on using the repository browser.