Changeset 7632:c11d6dbe6e54 in orange


Ignore:
Timestamp:
02/10/11 10:25:23 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
6e75393e108f94c7a737f79874f9fc0a489d86d8
Message:
  • removed function constructor, added new method instead
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/classification/wrappers.py

    r7616 r7632  
    1 import Orange.core as orange 
     1import Orange.core 
     2import Orange.evaluation.scoring as scoring 
     3import Orange.data 
     4import Orange.evaluation.testing 
     5import Orange.evaluation.scoring 
    26 
    3 class StepwiseLearner_Class: 
     7class StepwiseLearner(Orange.core.Learner): 
     8  def __new__(cls, data=None, weightId=None, **kwargs): 
     9      self = Orange.core.Learner.__new__(cls, **kwargs) 
     10      if data is not None: 
     11          self.__init__(**kwargs) 
     12          return self(data, weightId) 
     13      else: 
     14          return self 
     15       
    416  def __init__(self, **kwds): 
    5     import orngStat 
    617    self.removeThreshold = 0.3 
    718    self.addThreshold = 0.2 
    8     self.stat, self.statsign = orngStat.CA, 1 
     19    self.stat, self.statsign = scoring.CA, 1 
    920    self.__dict__.update(kwds) 
    1021 
    1122  def __call__(self, examples, weightID = 0, **kwds): 
    12     import orngTest, orngStat, statc 
     23    import Orange.evaluation.testing, Orange.evaluation.scoring, statc 
    1324     
    1425    self.__dict__.update(kwds) 
     
    1930    classVar = examples.domain.classVar 
    2031     
    21     indices = orange.MakeRandomIndicesCV(examples, folds = getattr(self, "folds", 10)) 
    22     domain = orange.Domain([], classVar) 
     32    indices = Orange.core.MakeRandomIndicesCV(examples, folds = getattr(self, "folds", 10)) 
     33    domain = Orange.data.Domain([], classVar) 
    2334 
    24     res = orngTest.testWithIndices([self.learner], orange.ExampleTable(domain, examples), indices) 
     35    res = Orange.evaluation.testing.testWithIndices([self.learner], Orange.data.Table(domain, examples), indices) 
    2536     
    2637    oldStat = self.stat(res)[0] 
    27     oldStats = [self.stat(x)[0] for x in orngStat.splitByIterations(res)] 
     38    oldStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.splitByIterations(res)] 
    2839    print ".", oldStat, domain 
    2940    stop = False 
     
    3344            bestStat = None 
    3445            for attr in domain.attributes: 
    35                 newdomain = orange.Domain(filter(lambda x: x!=attr, domain.attributes), classVar) 
    36                 res = orngTest.testWithIndices([self.learner], (orange.ExampleTable(newdomain, examples), weightID), indices) 
     46                newdomain = Orange.data.Domain(filter(lambda x: x!=attr, domain.attributes), classVar) 
     47                res = Orange.evaluation.testing.testWithIndices([self.learner], (Orange.data.Table(newdomain, examples), weightID), indices) 
    3748                 
    3849                newStat = self.stat(res)[0] 
    39                 newStats = [self.stat(x)[0] for x in orngStat.splitByIterations(res)]  
     50                newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.splitByIterations(res)]  
    4051                print "-", newStat, newdomain 
    4152                ## If stat has increased (ie newStat is better than bestStat) 
     
    4657                            bestStat, bestAttr, bestStats = newStat, newStats, attr 
    4758            if bestStat: 
    48                 domain = orange.Domain(filter(lambda x: x!=bestAttr, domain.attributes), classVar) 
     59                domain = Orange.data.Domain(filter(lambda x: x!=bestAttr, domain.attributes), classVar) 
    4960                oldStat, oldStats = bestStat, bestStats 
    5061                stop = False 
     
    5465        for attr in examples.domain.attributes: 
    5566            if not attr in domain.attributes: 
    56                 newdomain = orange.Domain(domain.attributes + [attr], classVar) 
    57                 res = orngTest.testWithIndices([self.learner], (orange.ExampleTable(newdomain, examples), weightID), indices) 
     67                newdomain = Orange.data.Domain(domain.attributes + [attr], classVar) 
     68                res = Orange.evaluation.testing.testWithIndices([self.learner], (Orange.data.Table(newdomain, examples), weightID), indices) 
    5869                 
    5970                newStat = self.stat(res)[0] 
    60                 newStats = [self.stat(x)[0] for x in orngStat.splitByIterations(res)]  
     71                newStats = [self.stat(x)[0] for x in Orange.evaluation.scoring.splitByIterations(res)]  
    6172                print "+", newStat, newdomain 
    6273 
     
    6576                    bestStat, bestStats, bestAttr = newStat, newStats, attr 
    6677        if bestAttr: 
    67             domain = orange.Domain(domain.attributes + [bestAttr], classVar) 
     78            domain = Orange.data.Domain(domain.attributes + [bestAttr], classVar) 
    6879            oldStat, oldStats = bestStat, bestStats 
    6980            stop = False 
    7081            print "added", bestAttr.name 
    7182 
    72     return self.learner(orange.ExampleTable(domain, examples), weightID) 
     83    return self.learner(Orange.data.Table(domain, examples), weightID) 
    7384 
    74 def StepwiseLearner(examples = None, weightID = None, **argkw): 
    75     sl = apply(StepwiseLearner_Class, (), argkw) 
    76     if examples: 
    77         return sl(examples, weightID) 
    78     else: 
    79         return sl 
Note: See TracChangeset for help on using the changeset viewer.