source: orange/Orange/data/discretization.py @ 9943:364085431ea7

Revision 9943:364085431ea7, 1.8 KB checked in by blaz <blaz.zupan@…>, 2 years ago (diff)

updates for discretization rst

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