Changeset 7764:773887c2a6e2 in orange for orange/orngImpute.py


Ignore:
Timestamp:
03/18/11 14:53:13 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
5ddd67ca8e82c904ae3837cdc2e4cc8d9856626b
Message:

Imputation for 2.5.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/orngImpute.py

    r7636 r7764  
    1 from Orange.feature.imputation import ImputeLearner as ImputeLearner 
    2 from Orange.feature.imputation import ImputeClassifier as ImputeClassifier 
     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 TracChangeset for help on using the changeset viewer.