Changeset 10575:2718a801a48e in orange
 Timestamp:
 03/19/12 20:03:27 (2 years ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/regression/linear.py
r10557 r10575 244 244 domain = table.domain 245 245 246 if numpy.std(y) < 10e6: # almost constant variable247 return Orange.regression.mean.MeanLearner(table)248 249 # set weights to the instances250 W = numpy.identity(n)251 246 if weight: 252 for i, ins in enumerate(table): 253 W[i, i] = float(ins[weight]) 254 255 compute_stats = self.compute_stats 247 weights = numpy.sqrt([float(ins[weight]) for ins in table]) 248 weights = weights.reshape(y.shape) 249 X = weights * X 250 y = weights * y 251 252 cov = dot(X.T, X) 253 254 if self.ridge_lambda: 255 cov += self.ridge_lambda * numpy.eye(m + self.intercept) 256 256 257 # adds some robustness by computing the pseudo inverse; 257 # normal inverse could fail due to singularity of the X.T * W * X 258 if self.ridge_lambda is None: 259 cov = pinv(dot(dot(X.T, W), X)) 260 else: 261 cov = pinv(dot(dot(X.T, W), X) + 262 self.ridge_lambda * numpy.eye(m + self.intercept)) 263 # TODO: find inferential properties of the estimators 264 compute_stats = False 265 D = dot(dot(cov, X.T), W) 258 # normal inverse could fail due to the singularity of X.T * X 259 invcov = pinv(cov) 260 D = dot(invcov, X.T) 266 261 coefficients = dot(D, y) 267 262 … … 275 270 std_coefficients = None 276 271 277 if compute_stats is False: 272 # TODO: find inferential properties of the estimators for ridge 273 if self.compute_stats is False or self.ridge_lambda: 278 274 return LinearRegression(domain.class_var, domain, 279 275 coefficients=coefficients, std_coefficients=std_coefficients, … … 289 285 sst = numpy.sum((y  mu_y) ** 2) 290 286 # sum of squares due to regression (explained variance) 291 ssr = numpy.sum((fitted  mu_y) **2)287 ssr = numpy.sum((fitted  mu_y) ** 2) 292 288 # error sum of squares (unexplaied variance) 293 289 sse = sst  ssr
Note: See TracChangeset
for help on using the changeset viewer.