Revision 9924:69d0ac45ad93, 3.6 KB checked in by janezd <janez.demsar@…>, 2 years ago (diff)

Line
1.. py:currentmodule:: Orange.core
2
3Value transformers are objects that take care of simple transformations
4of values. Discretization, for instance, creates a transformer that
5converts continuous values into discrete, while continuizers do the
6opposite. Classification trees use transformers for binarization where
7values of discrete attributes are converted into binary.
8
9These objects are most often constructed by other classes and only seldom
10manually.
11
12.. class TransformValue
13
14    The abstract root of the hierarchy of transformers provides the call
15    operator and chaining of transformers.
16
17    .. attribute subtransformer
18
19        The transformation that takes place prior to this.
20        This way, transformations can be chained.
21
22
23.. class Ordinal2Continuous
24
25    Converts ordinal values to continuous. For example, variable values
26    values `small`, `medium`, `large`, `extra large` (if given in
27    that order) would be, by default, converted to 0.0, 1.0, 2.0 and 3.0.
28    It is possible to add a factor by which the values are multiplied. If
29    the factor for the above case were 0.3333, the value would be
30    converted to 0, 0.3333, 0.6666 and 0.9999.
31
32    .. attribute factor
33
34        The factor by which the values are multiplied.
35
36    .. literalinclude:: transformvalue-o2c.py
37        :lines: 7-23
38
39    The values of attribute `age` (`young`, `pre-presbyopic` and
40    `presbyopic`) are transformed to 0.0, 1.0 and 2.0 in `age_c` and to
41    0, 0.5 and 1 in `age_cn`.
42
43
44.. class Discrete2Continuous
45
46    Converts a discrete value to a continuous so that some chosen
47    value is converted to 1.0 and all others to 0.0 or -1.0, depending on
48    the settings.
49
50    .. attribute value
51
52        The value that in converted to 1.0; others are converted to 0.0
53        or -1.0. Value needs to be specified by an integer index.
54
55    .. attribute zero_based
56
57        Decides whether the other values will be transformed to 0.0
58        (``True``, default) or -1.0 (``False``).
59        When ``False`` undefined values are transformed to 0.0;
60        otherwise, undefined values yield an error.
61
62    .. attribute invert
63
64        If ``True`` (default is ``False``), the transformations are
65        reversed - the selected ``value<`` becomes 0.0 (or -1.0)
66        and others 1.0.
67
68
69    The following script load the Monks 1 data set and constructs a new
70    attribute `e1` that will indicate whether `e` is 1 or not.
71
72    .. literalinclude transformvalue-d2c.py
73
74
75.. class NormalizeContinuous
76
77    Takes a continuous values and subtracts the ``average`` and
78    divides the difference by half of the ``span``.
79
80    .. attribute average
81
82        The value that is subtracted from the original.</DD>
83
84    .. span
85
86        The divisor
87
88    The following script "normalizes" all attribute in the Iris dataset by
89    subtracting the average value and dividing by the half of
90    deviation.
91
92    .. literalinclude transformvalue-nc.py
93        :lines: 1-17
94
95.. class MapIntValue
96
97    A discrete-to-discrete transformer that changes values according to the
98    given mapping. MapIntValue is used for binarization in decision trees.
99
100    .. attribute mapping
101
102        A mapping that determines the new value: ``v = mapping[v]``.
103        Undefined values remain undefined. Elements of the mapping
104        are  contains integer indices of values.
105
106    The following script transforms the value of `age` in dataset lenses
107    from 'young' to 'young', and from 'pre-presbyopic' and 'presbyopic' to
108    'old'.
109
110    .. literalinclude transformvalue-miv.py
111        :lines: 1-12
112
113    The mapping tells that the 0th value of `age` maps to the 0th of
114    `age_b`, and the 1st and 2nd value go to the 1st value of `age_b`.
Note: See TracBrowser for help on using the repository browser.