source: orange/Orange/feature/imputation.py @ 9806:01ddd2a2ff48

Revision 9806:01ddd2a2ff48, 1.7 KB checked in by tomazc <tomaz.curk@…>, 2 years ago (diff)

Updated documentation on Orange.feature.imputation.

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