@@ -310,6 +310,10 @@ class LinearRegression(LinearModel, RegressorMixin):
310310 copy_X : boolean, optional, default True
311311 If True, X will be copied; else, it may be overwritten.
312312
313+ n_jobs : The number of jobs to use for the computation.
314+ If -1 all CPUs are used. This will only provide speedup for
315+ n_targets > 1 and sufficient large problems.
316+
313317 Attributes
314318 ----------
315319 coef_ : array, shape (n_features, ) or (n_targets, n_features)
@@ -328,10 +332,11 @@ class LinearRegression(LinearModel, RegressorMixin):
328332
329333 """
330334
331- def __init__ (self , fit_intercept = True , normalize = False , copy_X = True ):
335+ def __init__ (self , fit_intercept = True , normalize = False , copy_X = True , n_jobs = 1 ):
332336 self .fit_intercept = fit_intercept
333337 self .normalize = normalize
334338 self .copy_X = copy_X
339+ self .n_jobs = n_jobs
335340
336341 def fit (self , X , y , n_jobs = 1 ):
337342 """
@@ -343,9 +348,6 @@ def fit(self, X, y, n_jobs=1):
343348 Training data
344349 y : numpy array of shape [n_samples, n_targets]
345350 Target values
346- n_jobs : The number of jobs to use for the computation.
347- If -1 all CPUs are used. This will only provide speedup for
348- n_targets > 1 and sufficient large problems
349351
350352 Returns
351353 -------
@@ -364,7 +366,7 @@ def fit(self, X, y, n_jobs=1):
364366 self .residues_ = out [3 ]
365367 else :
366368 # sparse_lstsq cannot handle y with shape (M, K)
367- outs = Parallel (n_jobs = n_jobs )(
369+ outs = Parallel (n_jobs = self . n_jobs )(
368370 delayed (lsqr )(X , y [:, j ].ravel ())
369371 for j in range (y .shape [1 ]))
370372 self .coef_ = np .vstack (out [0 ] for out in outs )
0 commit comments