Changeset 3713:a75a3ecadad5 in orange
 Timestamp:
 05/29/07 14:13:35 (7 years ago)
 Branch:
 default
 Convert:
 fae5f2c37c4f556a354aec24745f5663d112b601
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/orngMultivariatePrediction.py
r3674 r3713 2 2 import orngRegression 3 3 4 ''' 5 def MCLearner(baseLearner, data = None, Ncomp = None, listY = None, listX = None, weightID=0, **kwds): 6 l = apply(MCLearnerClass, (), kwds) 7 if data: 8 if baseLearner == 'PlsLearner': 9 l = l(data, Ncomp, listY, listX) 10 if baseLearner == 'SvmLearner': 11 l = l(data, listX, listY) 12 return l 13 ''' 4 class MultiClassPredictionLearner(object): 5 """(self, data, y, x=None)""" 6 def __new__(self, data=None, name='multivar pred', **kwds): 7 learner = object.__new__(self, **kwds) 8 if data: 9 learner.__init__(name) # force init 10 return learner(data) 11 else: 12 return learner # invokes the __init__ 14 13 15 class MCLearnerClass: 14 def __init__(self, name='multivar pred', baseLearner=orngRegression.LinearRegressionLearner): 15 self.name = name 16 self.baseLearner = baseLearner 17 18 def __call__(self, data, y, x=None, weight=None): 19 if y == None: 20 try: 21 y = [data.domain.classVar] 22 except: 23 import warnings 24 warnings.warn("multiclass learner requires either specification of response variables or a data domain with a class") 25 return None 26 if x == None: 27 print y 28 x = [v for v in data.domain.variables if v not in y] 16 29 17 def __call__(self, baseLearner, data, X, Y, PLSNcomp = 3): 30 models = [] 31 for a in y: 32 newDomain = orange.Domain(x, a) 33 newData = orange.ExampleTable(newDomain, data) 34 models.append(baseLearner(newData)) 35 return MultiClassPrediction(x=x, y=y, models=models) 36 37 class MultiClassPrediction: 38 def __init__(self, **kwds): 39 self.__dict__ = kwds 18 40 19 if baseLearner == 'PlsLearner': 20 lr = orngRegression.PLSRegressionLearner(data, PLSNcomp, Y, X) 21 return lr 22 if baseLearner == 'SvmLearner': 23 models = [] 24 for i in Y: 25 attr = list(X) 26 attr.append(i) 27 newDomain = orange.Domain([data.domain[a] for a in attr]) 28 newData = orange.ExampleTable(newDomain, data) 29 lr = orange.SVMLearner() 30 lr.svm_type=orange.SVMLearner.NU_SVR 31 model = lr(newData) 32 models.append(model) 33 return models 34 35 36 d = orange.ExampleTable('C://Delo//Python//Distance Learning//04curatedF05.tab') 37 ind = d.domain.index('smiles') 38 nd = orange.Domain(d.domain[0:ind1] + d.domain[ind+1:], 0) 39 data = orange.ExampleTable(nd, d) 40 41 lr = MCLearnerClass()('SvmLearner', data, ['growthC', 'growthE', 'dev', 'sporesC'], ['C','CC','CCC']) 41 def __call__(self, example): 42 return [m(example) for m in self.models]
Note: See TracChangeset
for help on using the changeset viewer.