Ignore:
Timestamp:
03/15/12 15:14:54 (2 years ago)
Author:
anzeh <anze.staric@…>
Branch:
default
Message:

Moved preprocess from Orange to Orange.data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeWidgets/Data/OWPreprocess.py

    r9671 r10542  
    1717import math 
    1818 
    19 from Orange.preprocess import * 
     19from Orange.data import preprocess 
    2020 
    2121def _gettype(obj): 
     
    7676    def getDiscretizer(self): 
    7777        if self.discInd == 0: 
    78             preprocessor = Preprocessor_discretizeEntropy(method=orange.EntropyDiscretization()) 
     78            preprocessor = preprocess.DiscretizeEntropy(method=orange.EntropyDiscretization()) 
    7979        elif self.discInd in [1, 2]: 
    8080            name, disc, kwds = self.DISCRETIZERS[self.discInd] 
    81             preprocessor = Preprocessor_discretize(method=disc(**dict([(key, getattr(self, key, val)) for key, val in kwds.items()]))) 
     81            preprocessor = preprocess.Discretize(method=disc(**dict([(key, getattr(self, key, val)) for key, 
     82                                                                                              val in kwds.items()]))) 
    8283        elif self.discInd == 3: 
    83             preprocessor = Preprocessor_removeContinuous() 
     84            preprocessor = preprocess.RemoveContinuous() 
    8485        return preprocessor 
    8586     
     
    120121    def getContinuizer(self): 
    121122        if self.contInd in [0, 1, 2, 4, 5]: 
    122             preprocessor = Preprocessor_continuize(multinomialTreatment=self.CONTINUIZERS[self.contInd][1]) 
     123            preprocessor = preprocess.Continuize(multinomialTreatment=self.CONTINUIZERS[self.contInd][1]) 
    123124        elif self.contInd == 3: 
    124             preprocessor = Preprocessor_removeDiscrete() 
     125            preprocessor = preprocess.RemoveDiscrete() 
    125126        return preprocessor 
    126127     
    127128    def setContinuizer(self, continuizer): 
    128         if isinstance(continuizer, Preprocessor_removeDiscrete): 
     129        if isinstance(continuizer, preprocess.RemoveDiscrete): 
    129130            self.contInd = 3 #Ignore all discrete 
    130         elif isinstance(continuizer,Preprocessor_continuize): 
     131        elif isinstance(continuizer,preprocess.Continuize): 
    131132            self.contInd = self.TREATMENT_TO_IND.get(continuizer.multinomialTreatment, 3) 
    132133     
    133     data = _pyqtProperty(Preprocessor_continuize, 
     134    data = _pyqtProperty(preprocess.Continuize, 
    134135                        fget=getContinuizer, 
    135136                        fset=setContinuizer, 
     
    155156        if self.methodInd in [0, 1, 2]: 
    156157            learner = self.IMPUTERS[self.methodInd][1]() 
    157             imputer = Preprocessor_imputeByLearner(learner=learner) 
     158            imputer = preprocess.ImputeByLearner(learner=learner) 
    158159        elif self.methodInd == 3: 
    159             imputer = orange.Preprocessor_dropMissing() 
     160            imputer = preprocess.DropMissing() 
    160161        return imputer 
    161162             
     
    163164    def setImputer(self, imputer): 
    164165        self.methodInd = 0 
    165         if isinstance(imputer, Preprocessor_imputeByLearner): 
     166        if isinstance(imputer, preprocess.ImputeByLearner): 
    166167            learner = imputer.learner 
    167168            dd = dict([(t, i) for i, (_, t) in enumerate(self.IMPUTERS)]) 
    168169            self.methodInd = dd.get(_gettype(learner), 0) 
    169         elif isinstance(imputer, orange.Preprocessor_dropMissing): 
     170        elif isinstance(imputer, preprocess.DropMissing): 
    170171            self.methodInd = 3 
    171172             
    172     data = _pyqtProperty(Preprocessor_imputeByLearner, 
     173    data = _pyqtProperty(preprocess.ImputeByLearner, 
    173174                        fget=getImputer, 
    174175                        fset=setImputer, 
     
    183184                ("Linear SVM weights", orngSVM.MeasureAttribute_SVMWeights)] 
    184185     
    185     FILTERS = [Preprocessor_featureSelection.bestN, 
    186                Preprocessor_featureSelection.bestP] 
     186    FILTERS = [preprocess.FeatureSelection.bestN, 
     187               preprocess.FeatureSelection.bestP] 
    187188     
    188189    def __init__(self, parent=None): 
     
    235236     
    236237    def getFeatureSelection(self): 
    237         return Preprocessor_featureSelection(measure=self.MEASURES[self.measureInd][1], 
     238        return preprocess.FeatureSelection(measure=self.MEASURES[self.measureInd][1], 
    238239                                             filter=self.FILTERS[self.selectBy], 
    239240                                             limit=self.bestP if self.selectBy  else self.bestN) 
    240241     
    241     data = _pyqtProperty(Preprocessor_featureSelection, 
     242    data = _pyqtProperty(preprocess.FeatureSelection, 
    242243                        fget=getFeatureSelection, 
    243244                        fset=setFeatureSelection, 
     
    245246         
    246247class SampleEditor(BaseEditor): 
    247     FILTERS = [Preprocessor_sample.selectNRandom, 
    248                Preprocessor_sample.selectPRandom] 
     248    FILTERS = [preprocess.Sample.selectNRandom, 
     249               preprocess.Sample.selectPRandom] 
    249250    def __init__(self, parent=None): 
    250251        BaseEditor.__init__(self, parent) 
     
    278279         
    279280    def getSampler(self): 
    280         return Preprocessor_sample(filter=self.FILTERS[self.methodInd], 
     281        return preprocess.Sample(filter=self.FILTERS[self.methodInd], 
    281282                                   limit=self.sampleN if self.methodInd == 0 else self.sampleP) 
    282283     
     
    291292        self.updateSpinStates() 
    292293             
    293     data = _pyqtProperty(Preprocessor_sample, 
     294    data = _pyqtProperty(preprocess.Sample, 
    294295                        fget=getSampler, 
    295296                        fset=setSampler, 
     
    302303         
    303304    #Preprocessor name replacement rules 
    304     REPLACE = {Preprocessor_discretize: "Discretize ({0.method})", 
    305                Preprocessor_discretizeEntropy: "Discretize (entropy)", 
    306                Preprocessor_removeContinuous: "Discretize (remove continuous)", 
    307                Preprocessor_continuize: "Continuize ({0.multinomialTreatment})", 
    308                Preprocessor_removeDiscrete: "Continuize (remove discrete)", 
    309                Preprocessor_impute: "Impute ({0.model})", 
    310                Preprocessor_imputeByLearner: "Impute ({0.learner})", 
    311                Preprocessor_dropMissing: "Remove missing", 
    312                Preprocessor_featureSelection: "Feature selection ({0.measure}, {0.filter}, {0.limit})", 
    313                Preprocessor_sample: "Sample ({0.filter}, {0.limit})", 
     305    REPLACE = {preprocess.Discretize: "Discretize ({0.method})", 
     306               preprocess.DiscretizeEntropy: "Discretize (entropy)", 
     307               preprocess.RemoveContinuous: "Discretize (remove continuous)", 
     308               preprocess.Continuize: "Continuize ({0.multinomialTreatment})", 
     309               preprocess.RemoveDiscrete: "Continuize (remove discrete)", 
     310               preprocess.Impute: "Impute ({0.model})", 
     311               preprocess.ImputeByLearner: "Impute ({0.learner})", 
     312               preprocess.DropMissing: "Remove missing", 
     313               preprocess.FeatureSelection: "Feature selection ({0.measure}, {0.filter}, {0.limit})", 
     314               preprocess.Sample: "Sample ({0.filter}, {0.limit})", 
    314315               orange.EntropyDiscretization: "entropy", 
    315316               orange.EquiNDiscretization: "freq, {0.numberOfIntervals}", 
     
    447448     
    448449    # Default preprocessors 
    449     preprocessors =[("Discretize", Preprocessor_discretizeEntropy, {}), 
    450                     ("Continuize", Preprocessor_continuize, {}), 
    451                     ("Impute", Preprocessor_impute, {}), 
    452                     ("Feature selection", Preprocessor_featureSelection, {}), 
    453                     ("Sample", Preprocessor_sample, {})] 
     450    preprocessors =[("Discretize", preprocess.DiscretizeEntropy, {}), 
     451                    ("Continuize", preprocess.Continuize, {}), 
     452                    ("Impute", preprocess.Impute, {}), 
     453                    ("Feature selection", preprocess.FeatureSelection, {}), 
     454                    ("Sample", preprocess.Sample, {})] 
    454455     
    455456    # Editor widgets for preprocessors 
    456     EDITORS = {Preprocessor_discretize: DiscretizeEditor, 
    457                Preprocessor_discretizeEntropy: DiscretizeEditor, 
    458                Preprocessor_removeContinuous: DiscretizeEditor, 
    459                Preprocessor_continuize: ContinuizeEditor, 
    460                Preprocessor_removeDiscrete: ContinuizeEditor, 
    461                Preprocessor_impute: ImputeEditor, 
    462                Preprocessor_imputeByLearner: ImputeEditor, 
    463                Preprocessor_dropMissing: ImputeEditor, 
    464                Preprocessor_featureSelection: FeatureSelectEditor, 
    465                Preprocessor_sample: SampleEditor, 
     457    EDITORS = {preprocess.Discretize: DiscretizeEditor, 
     458               preprocess.DiscretizeEntropy: DiscretizeEditor, 
     459               preprocess.RemoveContinuous: DiscretizeEditor, 
     460               preprocess.Continuize: ContinuizeEditor, 
     461               preprocess.RemoveDiscrete: ContinuizeEditor, 
     462               preprocess.Impute: ImputeEditor, 
     463               preprocess.ImputeByLearner: ImputeEditor, 
     464               preprocess.DropMissing: ImputeEditor, 
     465               preprocess.FeatureSelection: FeatureSelectEditor, 
     466               preprocess.Sample: SampleEditor, 
    466467               type(None): QWidget} 
    467468     
     
    476477         
    477478#        self.allSchemas = [PreprocessorSchema("Default" , [Preprocessor_discretize(method=orange.EntropyDiscretization()), Preprocessor_dropMissing()])] 
    478         self.allSchemas = [("Default" , [Preprocessor_discretizeEntropy(method=orange.EntropyDiscretization()), Preprocessor_dropMissing()], 0)] 
     479        self.allSchemas = [("Default" , [preprocess.DiscretizeEntropy(method=orange.EntropyDiscretization()), 
     480                                         preprocess.DropMissing()], 0)] 
    479481         
    480482        self.lastSelectedSchemaIndex = 0 
Note: See TracChangeset for help on using the changeset viewer.