Changeset 10851:b91d80df8bb3 in orange


Ignore:
Timestamp:
04/25/12 11:05:40 (2 years ago)
Author:
Miran@…
Branch:
default
Message:

[BUG] fixed a pickling bug in ensemble.forest._RandomForestTreeLearner

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/ensemble/forest.py

    r10769 r10851  
    3636    __new__ = Orange.utils._orange__new__(Orange.core.Learner) 
    3737 
    38     def __init__(self, base=None, rand=None): #pickle needs an empty init 
     38    def __init__(self, base=None, rand=None): # pickle needs an empty init 
    3939        self.base = base 
    4040        self.attributes = None 
     
    5050 
    5151_RandomForestSimpleTreeLearner = Orange.utils.deprecated_members({"weightID":"weight_id", "examples":"instances"})(_RandomForestSimpleTreeLearner) 
    52     
     52 
     53 
     54class _RandomForestTreeLearner(Orange.core.Learner): 
     55    """ A learner which wraps an ordinary TreeLearner with 
     56    a new split constructor. 
     57    """ 
     58 
     59    __new__ = Orange.utils._orange__new__(Orange.core.Learner) 
     60     
     61    def __init__(self, base=None, rand=None): # pickle needs an empty init 
     62        self.base = base 
     63        self.attributes = None 
     64        self.rand = rand 
     65        if not self.rand: #for all the built trees 
     66            self.rand = random.Random(0) 
     67 
     68    @deprecated_keywords({"examples":"instances"}) 
     69    def __call__(self, instances, weight=0): 
     70        """ A current tree learner is copied, modified and then used. 
     71        Modification: set a different split constructor, which uses 
     72        a random subset of attributes. 
     73        """ 
     74        bcopy = copy.copy(self.base) 
     75 
     76        #if base tree learner has no measure set 
     77        if not bcopy.measure: 
     78            bcopy.measure = Orange.feature.scoring.Gini() \ 
     79                if isinstance(instances.domain.class_var, Orange.feature.Discrete) \ 
     80                else Orange.feature.scoring.MSE() 
     81 
     82        bcopy.split = SplitConstructor_AttributeSubset(\ 
     83            bcopy.split, self.attributes, self.rand) 
     84 
     85        return bcopy(instances, weight=weight) 
     86 
     87 
     88 
    5389class RandomForestLearner(Orange.core.Learner): 
    5490    """ 
     
    163199                    domain=instances.domain, class_var=instances.domain.class_var, \ 
    164200                    class_vars=instances.domain.class_vars) 
    165  
    166              
     201            
    167202RandomForestLearner = Orange.utils.deprecated_members({"examples":"instances"})(RandomForestLearner) 
    168203 
     
    305340    def __reduce__(self): 
    306341        return type(self), (self.classifiers, self.name, self.domain, self.class_var, self.class_vars), dict(self.__dict__) 
     342 
    307343RandomForestClassifier = Orange.utils.deprecated_members({"resultType":"result_type", "classVar":"class_var", "example":"instance"})(RandomForestClassifier) 
    308344### MeasureAttribute_randomForests 
     
    512548          return set([]) 
    513549 
    514 class _RandomForestTreeLearner(Orange.core.Learner): 
    515     """ A learner which wraps an ordinary TreeLearner with 
    516     a new split constructor. 
    517     """ 
    518  
    519     __new__ = Orange.utils._orange__new__(Orange.core.Learner) 
    520       
    521     def __init__(self, base, rand): 
    522         self.base = base 
    523         self.attributes = None 
    524         self.rand = rand 
    525         if not self.rand: #for all the built trees 
    526             self.rand = random.Random(0) 
    527  
    528     @deprecated_keywords({"examples":"instances"}) 
    529     def __call__(self, instances, weight=0): 
    530         """ A current tree learner is copied, modified and then used. 
    531         Modification: set a different split constructor, which uses 
    532         a random subset of attributes. 
    533         """ 
    534         bcopy = copy.copy(self.base) 
    535  
    536         #if base tree learner has no measure set 
    537         if not bcopy.measure: 
    538             bcopy.measure = Orange.feature.scoring.Gini() \ 
    539                 if isinstance(instances.domain.class_var, Orange.feature.Discrete) \ 
    540                 else Orange.feature.scoring.MSE() 
    541  
    542         bcopy.split = SplitConstructor_AttributeSubset(\ 
    543             bcopy.split, self.attributes, self.rand) 
    544  
    545         return bcopy(instances, weight=weight) 
    546550 
    547551class SplitConstructor_AttributeSubset(orange.TreeSplitConstructor): 
Note: See TracChangeset for help on using the changeset viewer.