source: orange/Orange/data/discretization.py @ 11576:fb4551130eaf

Revision 11576:fb4551130eaf, 2.2 KB checked in by markotoplak, 11 months ago (diff)

Added missing dicretizers to the Orange hierarchy.

RevLine 
[9943]1import Orange
2
3from Orange.core import\
4    EquiNDiscretization as EqualFreq,\
[11576]5    EquiDistDiscretization as EqualWidth,\
6    EntropyDiscretization as Entropy,\
[9943]7    BiModalDiscretization as BiModal,\
8    Preprocessor_discretize
9
[11091]10
[9943]11class DiscretizeTable(object):
12    """Discretizes all continuous features of the data table.
13
[11091]14    :param data: Data to discretize.
[9943]15    :type data: :class:`Orange.data.Table`
16
[11091]17    :param features: Data features to discretize. `None` (default) to
18        discretize all features.
[10046]19    :type features: list of :class:`Orange.feature.Descriptor`
[9943]20
[11091]21    :param method: Feature discretization method.
22    :type method: :class:`Orange.feature.discretization.Discretization`
[9943]23
[11091]24    :param clean: Clean the data domain after discretization. If `True`,
25        features discretized to a constant will be removed. Useful only
26        for discretizers which infer number of discretization intervals
27        from data, like :class:`Orange.feature.discretize.Entropy`
28        (default: `True`).
29    :type clean: bool
[9943]30
31    """
[11091]32    def __new__(cls, data=None, features=None, discretize_class=False,
33                method=EqualFreq(n=3), clean=True):
[9943]34        if data is None:
35            self = object.__new__(cls)
36            return self
37        else:
[11091]38            self = cls(features=features, discretize_class=discretize_class,
39                       method=method, clean=clean)
[9943]40            return self(data)
41
[11091]42    def __init__(self, features=None, discretize_class=False,
43                 method=EqualFreq(n=3), clean=True):
[9943]44        self.features = features
45        self.discretize_class = discretize_class
46        self.method = method
47        self.clean = clean
48
49    def __call__(self, data):
[11091]50        pp = Preprocessor_discretize(attributes=self.features,
51                                     discretize_class=self.discretize_class)
[9943]52        pp.method = self.method
53        ddata = pp(data)
54
55        if self.clean:
[11091]56            features = [x for x in ddata.domain.features if len(x.values) > 1]
57            domain = Orange.data.Domain(features, ddata.domain.class_var,
58                                        class_vars=ddata.domain.class_vars)
59            return Orange.data.Table(domain, ddata)
[9943]60        else:
61            return ddata
Note: See TracBrowser for help on using the repository browser.