Changeset 3707:d78587e59a0c in orange
 Timestamp:
 05/28/07 10:46:38 (7 years ago)
 Branch:
 default
 Convert:
 3ff59c3120ec1e09839092a783887c044657c7db
 Location:
 orange
 Files:

 1 added
 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/orngRegression.py
r3693 r3707 98 98 yhat = dot(self.beta, ex[:1]) 99 99 dist = 0 # this should be distribution 100 100 101 101 if result_type == orange.GetValue: 102 102 return yhat 103 103 if result_type == orange.GetProbabilities: 104 104 return dist … … 141 141 class PLSRegressionLearner(object): 142 142 """PLSRegressionLearner(data, y, x=None, nc=None)""" 143 def __new__(self, data=None, y =None, x=None, nc = None, name='PLS regression', **kwds):143 def __new__(self, data=None, y = None, x = None, nc = None, name='PLS regression', **kwds): 144 144 learner = object.__new__(self, **kwds) 145 145 if data: 146 146 learner.__init__(name) # force init 147 return learner(data, y) 147 if x == None: 148 x = [v for v in data.domain.variables if v not in y] 149 if nc == None: 150 nc = len(x) 151 return learner(data,y,x,nc) 148 152 else: 149 153 return learner # invokes the __init__ … … 159 163 dataX = data.select(x) 160 164 dataY = data.select(y) 161 print y, dataY 162 165 163 166 # transformation to numpy arrays 164 167 X = dataX.toNumpy()[0] 168 n, mx = numpy.shape(X) 169 165 170 Y = dataY.toNumpy()[0] 166 167 # data dimensions 168 n, mx = numpy.shape(X) 169 my = numpy.shape(Y)[1] 171 172 # if Y is class 173 if Y == None: 174 Y = dataY.toNumpy()[1] 175 Y = Y.reshape((n,1)) 176 177 my = Y.shape[1] 178 170 179 171 180 # Zscores of original matrices … … 176 185 X,Y = standardize(X), standardize(Y) 177 186 178 P = numpy.empty((mx, Ncomp))179 C = numpy.empty((my, Ncomp))180 T = numpy.empty((n, Ncomp))181 U = numpy.empty((n, Ncomp))182 B = numpy.zeros(( Ncomp,Ncomp))183 W = numpy.empty((mx, Ncomp))187 P = numpy.empty((mx,nc)) 188 C = numpy.empty((my,nc)) 189 T = numpy.empty((n,nc)) 190 U = numpy.empty((n,nc)) 191 B = numpy.zeros((nc,nc)) 192 W = numpy.empty((mx,nc)) 184 193 E,F = X,Y 185 194 186 195 # main algorithm 187 for i in range( Ncomp):196 for i in range(nc): 188 197 u = numpy.random.random_sample((n,1)) 189 198 w = normalize(dot(E.T,u)) … … 214 223 Y = Y*numpy.std(Y, axis = 0)+ YMean 215 224 BPls = dot(dot(numpy.linalg.pinv(P.T),B),C.T) 216 return PLSRegression(domain=data .domain, BPls=BPls, YMean=YMean, YStd=YStd, XMean=XMean, XStd=XStd, name=self.name)225 return PLSRegression(domain=dataX.domain, BPls=BPls, YMean=YMean, YStd=YStd, XMean=XMean, XStd=XStd, name=self.name) 217 226 218 227 class PLSRegression:
Note: See TracChangeset
for help on using the changeset viewer.