source: orange/Orange/feature/imputation.py @ 10580:c4cbae8dcf8b

Revision 10580:c4cbae8dcf8b, 2.0 KB checked in by markotoplak, 2 years ago (diff)

Moved deprecation functions, progress bar support and environ into Orange.utils. Orange imports cleanly, although it is not tested yet.

Line 
1import Orange.core as orange
2from orange import\
3    Imputer as Imputer,\
4    ImputerConstructor as Constructor,\
5    ImputerConstructor_minimal as MinimalConstructor,\
6    ImputerConstructor_maximal as MaximalConstructor,\
7    ImputerConstructor_average as AverageConstructor,\
8    ImputerConstructor_model as ModelConstructor,\
9    ImputerConstructor_asValue as AsValueConstructor,\
10    ImputerConstructor_random as RandomConstructor,\
11    Imputer_defaults as Defaults,\
12    Imputer_model as Model,\
13    Imputer_random as Random,\
14    Imputer_asValue as AsValue,\
15    ImputeClassifier as Classifier
16
17import Orange.misc
18
19class ImputeLearner(orange.Learner):
20    def __new__(cls, data = None, weight_id = 0, **keyw):
21        self = orange.Learner.__new__(cls, **keyw)
22        self.dont_impute_classifier = False
23        self.__dict__.update(keyw)
24        if data:
25            return self.__call__(data, weight_id)
26        else:
27            return self
28       
29    def __call__(self, data, weight=0):
30        trained_imputer = self.imputer_constructor(data, weight)
31        imputed_data = trained_imputer(data, weight)
32        base_classifier = self.base_learner(imputed_data, weight)
33        if self.dont_impute_classifier:
34            return base_classifier
35        else:
36            return ImputeClassifier(base_classifier, trained_imputer)
37
38ImputeLearner = Orange.utils.deprecated_members(
39  {
40      "dontImputeClassifier": "dont_impute_classifier",
41      "imputerConstructor": "imputer_constructor",
42      "baseLearner": "base_learner",
43      "weightID": "weight_id"
44  })(ImputeLearner)
45
46
47class ImputeClassifier(orange.Classifier):
48    def __init__(self, base_classifier, imputer, **argkw):
49        self.base_classifier = base_classifier
50        self.imputer = imputer
51        self.__dict__.update(argkw)
52
53    def __call__(self, i, what=orange.GetValue):
54        return self.base_classifier(self.imputer(i), what)
55
56ImputeClassifier = Orange.utils.deprecated_members(
57  {
58      "baseClassifier": "base_classifier"
59  })(ImputeClassifier)
Note: See TracBrowser for help on using the repository browser.