source: orange/Orange/data/discretization.py @ 11586:5ba051127aac

Revision 11586:5ba051127aac, 2.1 KB checked in by markotoplak, 11 months ago (diff)

Discretization uses the correct module for discretization classes.

RevLine 
[9943]1import Orange
2
[11584]3from Orange.core import Preprocessor_discretize
[11091]4
[9943]5class DiscretizeTable(object):
6    """Discretizes all continuous features of the data table.
7
[11091]8    :param data: Data to discretize.
[9943]9    :type data: :class:`Orange.data.Table`
10
[11091]11    :param features: Data features to discretize. `None` (default) to
12        discretize all features.
[10046]13    :type features: list of :class:`Orange.feature.Descriptor`
[9943]14
[11091]15    :param method: Feature discretization method.
16    :type method: :class:`Orange.feature.discretization.Discretization`
[9943]17
[11091]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
[9943]24
25    """
[11091]26    def __new__(cls, data=None, features=None, discretize_class=False,
[11586]27                method=Orange.feature.discretization.EqualFreq(n=3), clean=True):
[9943]28        if data is None:
29            self = object.__new__(cls)
30            return self
31        else:
[11091]32            self = cls(features=features, discretize_class=discretize_class,
33                       method=method, clean=clean)
[9943]34            return self(data)
35
[11091]36    def __init__(self, features=None, discretize_class=False,
[11586]37                 method=Orange.feature.discretization.EqualFreq(n=3), clean=True):
[9943]38        self.features = features
39        self.discretize_class = discretize_class
40        self.method = method
41        self.clean = clean
42
43    def __call__(self, data):
[11091]44        pp = Preprocessor_discretize(attributes=self.features,
45                                     discretize_class=self.discretize_class)
[9943]46        pp.method = self.method
47        ddata = pp(data)
48
49        if self.clean:
[11091]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)
[9943]54        else:
55            return ddata
Note: See TracBrowser for help on using the repository browser.