This is documentation for Orange 2.7. For the latest documentation, see Orange 3.

Classifier from variable

ClassifierFromVar and ClassifierFromVarFD are helper classifiers used to compute variable’s values from another variables. They are used, for instance, in discretization of continuous variables.

ClassifierFromVarFD retrieves the feature value based on its position in the domain and ClassifierFromVar retrieves the feature with the given descriptor.

Both classifiers can be given a function to transform the value. In discretization, for instance, the transformer computes the corresponding discrete interval for a continuous value of the original variable.

class ClassifierFromVar(which_var[, transformer])

Return the value of variable which_var; transform it by the transformer, if it is given.

which_var

The descriptor of the feature whose value is returned.

transformer

The transformer for the value. It should be a class derived from TransformValue or a function written in Python.

transform_unknowns

Defines the treatment of missing values.

distribution_for_unknown

The distribution that is returned when the which_var‘s value is undefined and transform_unknowns is False.

__call__(inst[, result_type])

Return transformer(instance[which_var]). The value of which_var can be either an ordinary variable, a meta variable or a variable which is not defined for the instance but its descriptor has a get_value_from that can be used to compute the value.

If the feature is not found or its value is missing, the missing value is passed to the transformer if transform_unknowns is True. Otherwise, distribution_for_unknown is returned.

The following example demonstrates the use of the class on the Monk 1 dataset. It construct a new variable e1 that has a value of 1, when e is 1, and not 1 otherwise.

import Orange

monks = Orange.data.Table("monks-1")
e = monks.domain["e"]
e1 = Orange.feature.Discrete("e1", values = ["1", "not 1"])

def eTransformer(value):
    if int(value) == 0:
        return 0
    else:
        return 1

e1.get_value_from = Orange.classification.ClassifierFromVar()
e1.get_value_from.whichVar = e
e1.get_value_from.transformer = eTransformer

monks2 = monks.select(["a", "b", "e", e1, "y"])
for i in monks2:
    print i
class ClassifierFromVarFD

A class similar to ClassifierFromVar except that the variable is given by its index in the domain. The index can also be negative to denote a meta attribute.

The only practical difference between the two classes is that this does not compute the value of the variable from other variables through the descriptor’s Orange.feature.Descriptor.get_value_from.

domain(inherited from :obj:`ClassifierFromVarFD`)

The domain to which the position applies.

position

The position of the attribute in the domain or its meta-id.

transformer

The transformer for the value. It should be a class derived from Orange.data.utils.TransformValue or a function written in Python.

transform_unknowns

Defines the treatment of missing values.

distribution_for_unknown

The distribution that is returned when the which_var‘s value is undefined and transform_unknowns is False.

The use of this class is similar to that of ClassifierFromVar.

e1.get_value_from = Orange.classification.ClassifierFromVarFD()
e1.get_value_from.domain = monks.domain
e1.get_value_from.position = monks.domain.attributes.index(e)
e1.get_value_from.transformer = eTransformer