source: orange/Orange/data/discretization.py @ 11584:8763e1517159

Revision 11584:8763e1517159, 2.0 KB checked in by markotoplak, 11 months ago (diff)

Removed discretization classes from data/discretization (they should be in feature/discretization).

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