Ignore:
Timestamp:
02/25/12 22:53:57 (2 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Parents:
10375:e29f566e9513 (diff), 10367:058e9b1cc258 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/Orange.classification.classfromvar.rst

    r10363 r10376  
    77************************ 
    88 
    9 Classifiers from variable are used not to predict class values 
    10 but to compute variable's values from another variables. 
    11 For instance, when a continuous variable is discretized and replaced by 
    12 a discrete variable, an instance of a classifier from variable takes 
    13 care of automatic value computation when needed. 
     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. 
    1412 
    15 There are two classifiers from variable; the simpler :obj:`ClassifierFromVarFD` 
    16 supposes that example is from some fixed domain and the safer 
    17 :obj:`ClassifierFromVar` does not. 
     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. 
    1817 
    19 Both classifiers can be given a transformer that can modify the value. 
    20 In discretization, for instance, the transformer is responsible to compute 
    21 a discrete interval for a continuous value of the original variable. 
     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. 
    2222 
    2323 
    24 ClassifierFromVar 
    25 ================= 
    26  
    27 .. class:: ClassifierFromVar(which_var, transformer) 
     24.. class:: ClassifierFromVar(which_var[, transformer]) 
    2825     
    29     Compute variable's values from variable :obj:`~ClassifierFromVar.which_var` 
    30     using transformation defined by :obj:`~ClassifierFromVar.transformer`. 
    31  
     26    Return the value of variable :obj:`~ClassifierFromVar.which_var`; 
     27    transform it by the :obj:`~ClassifierFromVar.transformer`, if it 
     28    is given. 
     29  
    3230    .. attribute:: which_var 
    3331 
    34         The descriptor of the attribute whose value is to be returned. 
     32        The descriptor of the feature whose value is returned. 
    3533 
    3634    .. attribute:: transformer         
    3735 
    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. 
     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. 
    4143 
    4244    .. attribute:: distribution_for_unknown 
    4345 
    4446        The distribution that is returned when the 
    45         :obj:`~ClassifierFromVar.which_var`'s value is undefined. 
     47        :obj:`~ClassifierFromVar.which_var`'s value is undefined and 
     48        :obj:`~ClassifierFromVar.transform_unknowns` is ``False``. 
    4649 
    47 When given an instance, :obj:`ClassifierFromVar` will return 
    48 ``transformer(instance[which_var])``. 
    49 Attribute :obj:`~ClassifierFromVar.which_var` can be either an ordinary 
    50 variable, a meta variable or a variable which is not defined for the instance 
    51 but has :obj:`~Orange.feature.Descriptor.get_value_from` that can be used to 
    52 compute the value. If none goes through or if the value found is unknown, a 
    53 Value of subtype Distribution containing 
    54 :obj:`~ClassifierFromVar.distribution_for_unknown` is returned. 
     50    .. method:: __call__(inst[, result_type]) 
    5551 
    56 The class stores the domain version for the last example and its position in 
    57 the domain. If consecutive examples come from the same domain (which is usually 
    58 the case), :obj:`~Orange.classification.ClassifierFromVar` is just two simple 
    59 ifs slower than :obj:`~Orange.classification.ClassifierFromVarFD`. 
     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. 
    6058 
    61 As you might have guessed, the crucial component here is the transformer. 
    62 Let us, for sake of demonstration, load a ``monks-1`` dataset and construct an 
    63 attribute ``e1`` that will have value "1", when ``e`` is "1", and "not 1" when 
    64 ``e`` is different than 1. There are many ways to do it, and that same problem 
    65 is covered in different places in Orange documentation. Although the way 
    66 presented here is not the simplest, it will serve to demonstrate how 
    67 ClassifierFromVar works. 
     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. 
    6865 
     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. 
    6969 
    7070.. literalinclude:: code/classifier-from-var-example.py 
    7171    :lines: 1-19 
    7272 
    73 ClassifierFromVarFD 
    74 =================== 
     73 
    7574 
    7675.. class:: ClassifierFromVarFD 
    7776 
    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. 
     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`. 
    8587 
    8688    .. attribute:: domain (inherited from :obj:`ClassifierFromVarFD`) 
    8789     
    88         The domain on which the classifier operates. 
     90        The domain to which the :obj:`position` applies. 
    8991 
    9092    .. attribute:: position 
     
    9294        The position of the attribute in the domain or its meta-id. 
    9395 
    94     .. attribute:: transformer 
     96    .. attribute:: transformer         
    9597 
    96         The transformer for the value. 
     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. 
    97105 
    98106    .. attribute:: distribution_for_unknown 
    99107 
    100         The distribution that is returned when the which_var's value is undefined. 
     108        The distribution that is returned when the `which_var`'s value 
     109        is undefined and :obj:`transform_unknowns` is ``False``. 
    101110 
    102 When an instance is passed to :obj:`~Orange.classification.ClassifierFromVarFD`, 
    103 it is first checked whether it is from the correct domain; an exception is 
    104 raised if not. If the domain is OK, the corresponding attribute value is 
    105 retrieved, transformed and returned. 
     111    The use of this class is similar to that of  
     112    :obj:`~Orange.classification.ClassifierFromVar`. 
    106113 
    107 :obj:`ClassifierFromVarFD`'s twin brother, :obj:`ClassifierFromVar`, can also 
    108 handle variables that are not in the instances' domain or meta-variables, 
    109 but 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, 
    112 such functionality is obviously impossible. 
    113  
    114 To rewrite the above script to use :obj:`ClassifierFromVarFD`, 
    115 we need to set the domain and the ``e``'s index to position 
    116 (equivalent to setting which_var in :obj:`ClassifierFromVar`). 
    117 The initialization of :obj:`ClassifierFromVarFD` thus goes like this: 
    118  
    119 .. literalinclude:: code/classifier-from-var-example.py 
    120     :lines: 21-25 
     114    .. literalinclude:: code/classifier-from-var-example.py 
     115        :lines: 21-25 
  • docs/reference/rst/Orange.classification.classfromvar.rst

    r10373 r10376  
    2424.. class:: ClassifierFromVar(which_var[, transformer]) 
    2525     
    26     Return the value of variable :obj:`which_var`; transform it by the 
    27     :obj:`transformer`, if it is given. 
     26    Return the value of variable :obj:`~ClassifierFromVar.which_var`; 
     27    transform it by the :obj:`~ClassifierFromVar.transformer`, if it 
     28    is given. 
    2829  
    2930    .. attribute:: which_var 
     
    3435 
    3536        The transformer for the value. It should be a class derived 
    36         from :obj:`Orange.data.utils.TransformValue` or a function 
     37        from :obj:`~Orange.data.utils.TransformValue` or a function 
    3738        written in Python. 
    3839 
     
    4344    .. attribute:: distribution_for_unknown 
    4445 
    45         The distribution that is returned when the `which_var`'s value 
    46         is undefined and :obj:`transform_unknowns` is ``False``. 
     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``. 
    4749 
    4850    .. method:: __call__(inst[, result_type]) 
    4951 
    5052        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 
     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 
    5456        :obj:`~Orange.feature.Descriptor.get_value_from` that can be 
    5557        used to compute the value. 
     
    5759        If the feature is not found or its value is missing, the 
    5860        missing value is passed to the transformer if 
    59         :obj:`transform_unknowns` is ``True``. Otherwise, 
    60         :obj:`distribution_for_unknown` is returned. 
     61        :obj:`~ClassifierFromVar.transform_unknowns` is 
     62        ``True``. Otherwise, 
     63        :obj:`~ClassifierFromVar.distribution_for_unknown` is 
     64        returned. 
    6165 
    6266The following example demonstrates the use of the class on the Monk 1 
     
    7175.. class:: ClassifierFromVarFD 
    7276 
     77 
    7378    A class similar to 
    7479    :obj:`~Orange.classification.ClassifierFromVar` except that the 
     
    8186    :obj:`Orange.feature.Descriptor.get_value_from`. 
    8287 
    83     .. attribute:: domain (inherited from ClassifierFromVarFD) 
     88    .. attribute:: domain (inherited from :obj:`ClassifierFromVarFD`) 
    8489     
    8590        The domain to which the :obj:`position` applies. 
Note: See TracChangeset for help on using the changeset viewer.