Changeset 9961:b4e8e9784a5d in orange


Ignore:
Timestamp:
02/07/12 20:14:23 (2 years ago)
Author:
ales_erjavec
Branch:
default
rebase_source:
3ee913509644ecd7dc2c69437579bd4cd71d48ab
Message:

Fixed camelCase names in the interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/classification/wrappers.py

    r9671 r9961  
    55import Orange.evaluation.scoring 
    66 
     7from Orange.misc import deprecated_members 
     8 
    79class StepwiseLearner(Orange.core.Learner): 
    8   def __new__(cls, data=None, weightId=None, **kwargs): 
     10  def __new__(cls, data=None, weight_id=None, **kwargs): 
    911      self = Orange.core.Learner.__new__(cls, **kwargs) 
    1012      if data is not None: 
    1113          self.__init__(**kwargs) 
    12           return self(data, weightId) 
     14          return self(data, weight_id) 
    1315      else: 
    1416          return self 
    1517       
    1618  def __init__(self, **kwds): 
    17     self.removeThreshold = 0.3 
    18     self.addThreshold = 0.2 
     19    self.remove_threshold = 0.3 
     20    self.add_threshold = 0.2 
    1921    self.stat, self.statsign = scoring.CA, 1 
    20     self.__dict__.update(kwds) 
     22    for name, val in kwds.items(): 
     23        setattr(self, name, val) 
    2124 
    22   def __call__(self, examples, weightID = 0, **kwds): 
     25  def __call__(self, data, weight_id = 0, **kwds): 
    2326    import Orange.evaluation.testing, Orange.evaluation.scoring, statc 
    2427     
    2528    self.__dict__.update(kwds) 
    2629 
    27     if self.removeThreshold < self.addThreshold: 
    28         raise ValueError("'removeThreshold' should be larger or equal to 'addThreshold'") 
     30    if self.remove_threshold < self.add_threshold: 
     31        raise ValueError("'remove_threshold' should be larger or equal to 'add_threshold'") 
    2932 
    30     classVar = examples.domain.classVar 
     33    classVar = data.domain.classVar 
    3134     
    32     indices = Orange.core.MakeRandomIndicesCV(examples, folds = getattr(self, "folds", 10)) 
     35    indices = Orange.core.MakeRandomIndicesCV(data, folds = getattr(self, "folds", 10)) 
    3336    domain = Orange.data.Domain([], classVar) 
    3437 
    35     res = Orange.evaluation.testing.test_with_indices([self.learner], Orange.data.Table(domain, examples), indices) 
     38    res = Orange.evaluation.testing.test_with_indices([self.learner], Orange.data.Table(domain, data), indices) 
    3639     
    3740    oldStat = self.stat(res)[0] 
    38     oldStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.splitByIterations(res)] 
     41    oldStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.split_by_iterations(res)] 
    3942    print ".", oldStat, domain 
    4043    stop = False 
     
    4548            for attr in domain.attributes: 
    4649                newdomain = Orange.data.Domain(filter(lambda x: x!=attr, domain.attributes), classVar) 
    47                 res = Orange.evaluation.testing.test_with_indices([self.learner], (Orange.data.Table(newdomain, examples), weightID), indices) 
     50                res = Orange.evaluation.testing.test_with_indices([self.learner], (Orange.data.Table(newdomain, data), weight_id), indices) 
    4851                 
    4952                newStat = self.stat(res)[0] 
    50                 newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.splitByIterations(res)]  
     53                newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.split_by_iterations(res)]  
    5154                print "-", newStat, newdomain 
    5255                ## If stat has increased (ie newStat is better than bestStat) 
     
    5457                    if cmp(newStat, oldStat) == self.statsign: 
    5558                        bestStat, bestStats, bestAttr = newStat, newStats, attr 
    56                     elif statc.wilcoxont(oldStats, newStats)[1] > self.removeThreshold: 
     59                    elif statc.wilcoxont(oldStats, newStats)[1] > self.remove_threshold: 
    5760                            bestStat, bestAttr, bestStats = newStat, newStats, attr 
    5861            if bestStat: 
     
    6366 
    6467        bestStat, bestAttr = oldStat, None 
    65         for attr in examples.domain.attributes: 
     68        for attr in data.domain.attributes: 
    6669            if not attr in domain.attributes: 
    6770                newdomain = Orange.data.Domain(domain.attributes + [attr], classVar) 
    68                 res = Orange.evaluation.testing.test_with_indices([self.learner], (Orange.data.Table(newdomain, examples), weightID), indices) 
     71                res = Orange.evaluation.testing.test_with_indices([self.learner], (Orange.data.Table(newdomain, data), weight_id), indices) 
    6972                 
    7073                newStat = self.stat(res)[0] 
    71                 newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.splitByIterations(res)]  
     74                newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.split_by_iterations(res)]  
    7275                print "+", newStat, newdomain 
    7376 
    7477                ## If stat has increased (ie newStat is better than bestStat) 
    75                 if cmp(newStat, bestStat) == self.statsign and statc.wilcoxont(oldStats, newStats)[1] < self.addThreshold: 
     78                if cmp(newStat, bestStat) == self.statsign and statc.wilcoxont(oldStats, newStats)[1] < self.add_threshold: 
    7679                    bestStat, bestStats, bestAttr = newStat, newStats, attr 
    7780        if bestAttr: 
     
    8184            print "added", bestAttr.name 
    8285 
    83     return self.learner(Orange.data.Table(domain, examples), weightID) 
     86    return self.learner(Orange.data.Table(domain, data), weight_id) 
    8487 
     88StepwiseLearner = deprecated_members( 
     89                    {"removeThreshold": "remove_threshold", 
     90                     "addThreshold": "add_threshold"}, 
     91                    )(StepwiseLearner) 
Note: See TracChangeset for help on using the changeset viewer.