Ignore:
Timestamp:
02/06/12 13:25:39 (2 years ago)
Author:
crt.gorup@…
Branch:
default
rebase_source:
52ef560e460d6dbc43513f55f66381fafdd802f1
Message:

Removed camelCase and added deprecated decorators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/ensemble/forest.py

    r9697 r9733  
    55import random 
    66import copy 
     7from Orange.misc import deprecated_keywords 
    78 
    89def _default_small_learner(attributes=None, rand=None, base=None): 
     
    2930  
    3031class _RandomForestSimpleTreeLearner(Orange.core.Learner): 
    31     """ A learner which wraps an ordinary SimpleTreeLearner.  Sets the 
     32    """A learner which wraps an ordinary SimpleTreeLearner.  Sets the 
    3233    skip_prob so that the number of randomly chosen features for each 
    33     split is  (on average) as specified.  """ 
    34  
    35     def __new__(cls, examples = None, weightID = 0, **argkw): 
     34    split is  (on average) as specified.""" 
     35 
     36    def __new__(cls, instances = None, weight_id = 0, **argkw): 
    3637        self = Orange.core.Learner.__new__(cls, **argkw) 
    37         if examples: 
     38        if instances: 
    3839            self.__init__(**argkw) 
    39             return self.__call__(examples, weightID) 
     40            return self.__call__(instances, weight_id) 
    4041        else: 
    4142            return self 
     
    4647        self.rand = rand 
    4748     
    48     def __call__(self, examples, weight=0): 
     49    def __call__(self, instances, weight=0): 
    4950        osp,orand = self.base.skip_prob, self.base.random_generator 
    50         self.base.skip_prob = 1-float(self.attributes)/len(examples.domain.attributes) 
     51        self.base.skip_prob = 1-float(self.attributes)/len(instances.domain.attributes) 
    5152        self.base.random_generator = self.rand 
    52         r = self.base(examples, weight) 
     53        r = self.base(instances, weight) 
    5354        self.base.skip_prob, self.base.random_generator = osp, orand 
    5455        return r 
     56_RandomForestSimpleTreeLearner = Orange.misc.deprecated_members({"weightID":"weight_id", "examples":"instances"})(_RandomForestSimpleTreeLearner) 
    5557    
    5658class RandomForestLearner(orange.Learner): 
     
    170172        return RandomForestClassifier(classifiers = classifiers, name=self.name,\ 
    171173                    domain=instances.domain, class_var=instances.domain.class_var) 
    172   
     174RandomForestLearner = Orange.misc.deprecated_members({"examples":"instances"})(RandomForestLearner) 
    173175 
    174176class RandomForestClassifier(orange.Classifier): 
     
    202204        self.__dict__.update(kwds) 
    203205 
    204     def __call__(self, instance, resultType = orange.GetValue): 
     206    def __call__(self, instance, result_type = orange.GetValue): 
    205207        """ 
    206208        :param instance: instance to be classified. 
     
    221223         
    222224            # voting for class probabilities 
    223             if resultType == orange.GetProbabilities or resultType == orange.GetBoth: 
     225            if result_type == orange.GetProbabilities or result_type == orange.GetBoth: 
    224226                prob = [0.] * len(self.domain.class_var.values) 
    225227                for c in self.classifiers: 
     
    234236            # this may not be the same class as one obtaining the 
    235237            # highest probability through probability voting 
    236             if resultType == orange.GetValue or resultType == orange.GetBoth: 
     238            if result_type == orange.GetValue or result_type == orange.GetBoth: 
    237239                cfreq = [0] * len(self.domain.class_var.values) 
    238240                for c in self.classifiers: 
     
    241243                cvalue = Orange.data.Value(self.domain.class_var, index) 
    242244     
    243             if resultType == orange.GetValue: return cvalue 
    244             elif resultType == orange.GetProbabilities: return cprob 
     245            if result_type == orange.GetValue: return cvalue 
     246            elif result_type == orange.GetProbabilities: return cprob 
    245247            else: return (cvalue, cprob) 
    246248         
     
    249251         
    250252            # voting for class probabilities 
    251             if resultType == orange.GetProbabilities or resultType == orange.GetBoth: 
     253            if result_type == orange.GetProbabilities or result_type == orange.GetBoth: 
    252254                probs = [c(instance, orange.GetBoth) for c in self.classifiers] 
    253255                cprob = dict() 
     
    262264                 
    263265            # gather average class value 
    264             if resultType == orange.GetValue or resultType == orange.GetBoth: 
     266            if result_type == orange.GetValue or result_type == orange.GetBoth: 
    265267                values = [c(instance).value for c in self.classifiers] 
    266268                cvalue = Orange.data.Value(self.domain.class_var, sum(values) / len(self.classifiers)) 
    267269             
    268             if resultType == orange.GetValue: return cvalue 
    269             elif resultType == orange.GetProbabilities: return cprob 
     270            if result_type == orange.GetValue: return cvalue 
     271            elif result_type == orange.GetProbabilities: return cprob 
    270272            else: return (cvalue, cprob) 
    271273             
    272274    def __reduce__(self): 
    273275        return type(self), (self.classifiers, self.name, self.domain, self.class_var), dict(self.__dict__) 
    274  
     276RandomForestClassifier = Orange.misc.deprecated_members({"resultType":"result_type", "classVar":"class_var", "example":"instance"})(RandomForestClassifier) 
    275277### MeasureAttribute_randomForests 
    276278 
     
    326328        else: 
    327329            self.learner = learner 
    328    
    329     def __call__(self, feature, instances, apriorClass=None): 
     330 
     331    @deprecated_keywords({"apriorClass":"aprior_class"}) 
     332    def __call__(self, feature, instances, aprior_class=None): 
    330333        """ 
    331334        Return importance of a given feature. 
     
    339342        :type instances: :class:`Orange.data.Table` 
    340343         
    341         :param apriorClass: not used! 
     344        :param aprior_class: not used! 
    342345         
    343346        """ 
     
    354357        else: 
    355358          raise Exception("MeasureAttribute_rf can not be called with (\ 
    356                 contingency,classDistribution, apriorClass) as fuction arguments.") 
     359                contingency,classDistribution, aprior_class) as fuction arguments.") 
    357360 
    358361        self._buffer(instances) 
     
    482485    a new split constructor. 
    483486    """ 
    484  
    485     def __new__(cls, examples = None, weightID = 0, **argkw): 
     487    @deprecated_keywords({"weightID":"weight_id", "examples":"instances"}) 
     488    def __new__(cls, instances = None, weight_id = 0, **argkw): 
    486489        self = Orange.core.Learner.__new__(cls, **argkw) 
    487         if examples: 
     490        if instances: 
    488491            self.__init__(**argkw) 
    489             return self.__call__(examples, weightID) 
     492            return self.__call__(instances, weight_id) 
    490493        else: 
    491494            return self 
     
    497500        if not self.rand: #for all the built trees 
    498501            self.rand = random.Random(0) 
    499      
    500     def __call__(self, examples, weight=0): 
     502 
     503    @deprecated_keywords({"examples":"instances"}) 
     504    def __call__(self, instances, weight=0): 
    501505        """ A current tree learner is copied, modified and then used. 
    502506        Modification: set a different split constructor, which uses 
     
    508512        if not bcopy.measure: 
    509513            bcopy.measure = Orange.feature.scoring.Gini() \ 
    510                 if isinstance(examples.domain.class_var, Orange.data.variable.Discrete) \ 
     514                if isinstance(instances.domain.class_var, Orange.data.variable.Discrete) \ 
    511515                else Orange.feature.scoring.MSE() 
    512516 
     
    514518            bcopy.split, self.attributes, self.rand) 
    515519 
    516         return bcopy(examples, weight=weight) 
     520        return bcopy(instances, weight=weight) 
    517521 
    518522class SplitConstructor_AttributeSubset(orange.TreeSplitConstructor): 
     
    524528            self.rand = random.Random(0) 
    525529 
    526     def __call__(self, gen, weightID, contingencies, apriori, candidates, clsfr): 
     530    @deprecated_keywords({"weightID":"weight_id"}) 
     531    def __call__(self, gen, weight_id, contingencies, apriori, candidates, clsfr): 
    527532        # if number of features for subset is not set, use square root 
    528533        cand = [1]*int(self.attributes) + [0]*(len(candidates) - int(self.attributes)) 
     
    530535        # instead with all features, we will invoke split constructor  
    531536        # only for the subset of a features 
    532         t = self.scons(gen, weightID, contingencies, apriori, cand, clsfr) 
     537        t = self.scons(gen, weight_id, contingencies, apriori, cand, clsfr) 
    533538        return t 
Note: See TracChangeset for help on using the changeset viewer.