source: orange/orange/orngImpute.py @ 7764:773887c2a6e2

Revision 7764:773887c2a6e2, 1.1 KB checked in by markotoplak, 3 years ago (diff)

Imputation for 2.5.

Line 
1#FOR COMPATIBILITY (orange 2.5)
2import orange
3
4class ImputeLearner(orange.Learner):
5    def __new__(cls, examples = None, weightID = 0, **keyw):
6        self = orange.Learner.__new__(cls, **keyw)
7        self.dontImputeClassifier = False
8        self.__dict__.update(keyw)
9        if examples:
10            return self.__call__(examples, weightID)
11        else:
12            return self
13       
14    def __call__(self, data, weight=0):
15        trained_imputer = self.imputerConstructor(data, weight)
16        imputed_data = trained_imputer(data, weight)
17        baseClassifier = self.baseLearner(imputed_data, weight)
18        if self.dontImputeClassifier:
19            return baseClassifier
20        else:
21            return ImputeClassifier(baseClassifier, trained_imputer)
22
23class ImputeClassifier(orange.Classifier):
24    def __init__(self, baseClassifier, imputer, **argkw):
25        self.baseClassifier = baseClassifier
26        self.imputer = imputer
27        self.__dict__.update(argkw)
28
29    def __call__(self, ex, what=orange.GetValue):
30        return self.baseClassifier(self.imputer(ex), what)
Note: See TracBrowser for help on using the repository browser.