source: orange/docs/reference/rst/Orange.classification.classfromvar.rst @ 10135:9d777256cb99

Revision 10135:9d777256cb99, 4.8 KB checked in by Matija Polajnar <matija.polajnar@…>, 2 years ago (diff)

Proper Orange.feature.classification removal.

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:`~Orange.classification.ClassifierFromVarFD`
16supposes that example is from some fixed domain and the safer
17:obj:`~Orange.classification.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 which_var using
30    transformation defined by 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        TransformValue, but you can also use a callback function.
40
41    .. attribute:: distribution_for_unknown
42
43        The distribution that is returned when the which_var's value is undefined.
44
45When given an instance, :obj:`~Orange.classification.ClassifierFromVar` will return
46transformer(instance[which_var]). Attribute which_var can be either an ordinary variable,
47a meta variable or a variable which is not defined for the instance but has getValueFrom
48that can be used to compute the value. If none goes through or if the value found is unknown,
49a Value of subtype Distribution containing distributionForUnknown is returned.
50
51The class stores the domain version for the last example and its position in the domain.
52If consecutive examples come from the same domain (which is usually the case),
53:obj:`~Orange.classification.ClassifierFromVar` is just two simple ifs slower than
54:obj:`~Orange.classification.ClassifierFromVarFD`.
55
56As you might have guessed, the crucial component here is the transformer.
57Let us, for sake of demonstration, load a Monk 1 dataset and construct an attribute
58e1 that will have value "1", when e is "1", and "not 1" when e is different than 1.
59There are many ways to do it, and that same problem is covered in different places
60in Orange documentation. Although the way presented here is not the simplest,
61it will serve to demonstrate how ClassifierFromVar works.
62
63
64.. literalinclude:: code/classifier-from-var-example.py
65    :lines: 1-19
66
67ClassifierFromVarFD
68===================
69
70.. class:: ClassifierFromVarFD
71
72    :obj:`~Orange.classification.ClassifierFromVarFD` is very similar to :obj:`~Orange.classification.ClassifierFromVar` except that the variable
73    is not given as a descriptor (like which_var) but as an index. The index can be
74    either a position of the variable in the domain or a meta-id. Given that :obj:`~Orange.classification.ClassifierFromVarFD`
75    is practically no faster than :obj:`~Orange.classification.ClassifierFromVar` (and can in future even be merged with the latter),
76    you should seldom need to use the class.
77
78    .. attribute:: domain (inherited from ClassifierFromVarFD)
79   
80        The domain on which the classifier operates.
81
82    .. attribute:: position
83
84        The position of the attribute in the domain or its meta-id.
85
86    .. attribute:: transformer
87
88        The transformer for the value.
89
90    .. attribute:: distribution_for_unknown
91
92        The distribution that is returned when the which_var's value is undefined.
93
94When an example is passed to :obj:`~Orange.classification.ClassifierFromVarFD`,
95it is first checked whether it is
96from the correct domain; an exception is raised if not. If the domain is OK,
97the corresponding attribute value is retrieved, transformed and returned.
98
99:obj:`~Orange.classification.ClassifierFromVarFD`'s twin brother, :obj:`~Orange.classification.ClassifierFromVar`, can also handle variables that
100are not in the instances' domain or meta-variables, but can be computed therefrom by using
101their getValueFrom. Since :obj:`~Orange.classification.ClassifierFromVarFD` doesn't store attribute descriptor but
102only an index, such functionality is obviously impossible.
103
104To rewrite the above script to use :obj:`~Orange.classification.ClassifierFromVarFD`,
105we need to set the domain and the e's index to position
106(equivalent to setting which_var in :obj:`~Orange.classification.ClassifierFromVar`).
107The initialization of :obj:`~Orange.classification.ClassifierFromVarFD` thus goes like this:
108
109.. literalinclude:: code/classifier-from-var-example.py
110    :lines: 21-25
Note: See TracBrowser for help on using the repository browser.