source: orange/orange/Orange/regression/base.py @ 9241:7b029ad947e9

Revision 9241:7b029ad947e9, 2.9 KB checked in by ales_erjavec <ales.erjavec@…>, 2 years ago (diff)

Fixed a typo.

Line 
1"""\
2====================================
3Basic regression learner (``basic``)
4====================================
5
6.. index:: regression
7
8.. autoclass:: BaseRegressionLearner
9    :members:
10
11"""
12
13import Orange
14
15class BaseRegressionLearner(Orange.core.Learner):
16    """ Base Regression Learner "learns" how to treat the discrete
17        variables and missing data.
18    """
19
20    def __new__(cls, table=None, weight_id=None, **kwds):
21        learner = Orange.core.Learner.__new__(cls, **kwds)
22        if table is not None:
23            learner.__init__(**kwds) 
24            return learner(table, weight_id)
25        else:
26            return learner     
27
28    def __init__(self):
29        pass
30
31    def set_imputer(self, imputer=None):
32        """ Sets the imputer for missing values.
33
34        :param imputer: function which imputes the missing values,
35            if None, the default imputer: mean for the continuous variables
36            and most frequent value (majority) for discrete variables
37        :type imputer: None or Orange.feature.imputation.ImputerConstructor_model   
38        """
39        if imputer is not None:
40            imputer = imputer
41        else: # default imputer
42            self.imputer = Orange.feature.imputation.ImputerConstructor_model()
43            self.imputer.learner_continuous = Orange.regression.mean.MeanLearner()
44            self.imputer.learner_discrete = Orange.classification.majority.MajorityLearner()
45
46    def set_continuizer(self, continuizer=None):
47        """ Sets the continuizer of the discrete variables
48
49        :param continuizer: function which replaces the categorical (dicrete)
50            variables with numerical variables. If None, the default continuizer
51            is used
52        :type continuizer: None or Orange.feature.continuization.DomainContinuizer
53        """
54        if continuizer is not None:
55            self.continuizer = continuizer
56        else: # default continuizer
57            self.continuizer = Orange.feature.continuization.DomainContinuizer()
58            self.continuizer.multinomial_treatment = self.continuizer.FrequentIsBase
59            self.continuizer.zero_based = True
60
61    def impute_table(self, table):
62        """ Imputes missing values.
63        Returns a new :class:`Orange.data.Table` object
64
65        :param table: data instances.
66        :type table: :class:`Orange.data.Table`
67        """
68        if table.has_missing_values():
69            imputer = self.imputer(table)
70            table = imputer(table)
71        return table
72
73    def continuize_table(self, table):
74        """ Continuizes the discrete variables.
75        Returns a new :class:`Orange.data.Table` object
76
77        :param table: data instances.
78        :type table: :class:`Orange.data.Table`
79        """
80        if table.domain.has_discrete_attributes():
81            newDomain = self.continuizer(table)
82            table = table.translate(newDomain)
83        return table
Note: See TracBrowser for help on using the repository browser.