8000 FIX : n_jobs was missing from LassoCV · jwchennlp/scikit-learn@7013e24 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7013e24

Browse files
committed
FIX : n_jobs was missing from LassoCV
1 parent a64ec51 commit 7013e24

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

doc/tutorial/statistical_inference/model_selection.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ automatically by cross-validation::
195195
>>> y_diabetes = diabetes.target
196196
>>> lasso.fit(X_diabetes, y_diabetes)
197197
LassoCV(alphas=None, copy_X=True, cv=None, eps=0.001, fit_intercept=True,
198-
max_iter=1000, n_alphas=100, normalize=False, precompute='auto',
199-
tol=0.0001, verbose=False)
198+
max_iter=1000, n_alphas=100, n_jobs=1, normalize=False, positive=False,
199+
precompute='auto', tol=0.0001, verbose=False)
200200
>>> # The estimator chose automatically its lambda:
201201
>>> lasso.alpha_ # doctest: +ELLIPSIS
202202
0.01229...

sklearn/linear_model/coordinate_descent.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ class LinearModelCV(six.with_metaclass(ABCMeta, LinearModel)):
861861
@abstractmethod
862862
def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
863863
normalize=False, precompute='auto', max_iter=1000, tol=1e-4,
864-
copy_X=True, cv=None, verbose=False, positive=False):
864+
copy_X=True, cv=None, verbose=False, n_jobs=1,
865+
positive=False):
865866
self.eps = eps
866867
self.n_alphas = n_alphas
867868
self.alphas = alphas
@@ -873,6 +874,7 @@ def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
873874
self.copy_X = copy_X
874875
self.cv = cv
875876
self.verbose = verbose
877+
self.n_jobs = n_jobs
876878
self.positive = positive
877879

878880
def fit(self, X, y):
@@ -1052,6 +1054,11 @@ class LassoCV(LinearModelCV, RegressorMixin):
10521054
verbose : bool or integer
10531055
amount of verbosity
10541056
1057+
n_jobs : integer, optional
1058+
Number of CPUs to use during the cross validation. If ``-1``, use
1059+
all the CPUs. Note that this is used only if multiple values for
1060+
l1_ratio are given.
1061+
10551062
positive : bool, optional
10561063
If positive, restrict regression coefficients to be positive
10571064
@@ -1101,16 +1108,16 @@ class LassoCV(LinearModelCV, RegressorMixin):
11011108
LassoLarsCV
11021109
"""
11031110
path = staticmethod(lasso_path)
1104-
n_jobs = 1
11051111

11061112
def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
11071113
normalize=False, precompute='auto', max_iter=1000, tol=1e-4,
1108-
copy_X=True, cv=None, verbose=False, positive=False):
1114+
copy_X=True, cv=None, verbose=False, n_jobs=1,
1115+
positive=False):
11091116
super(LassoCV, self).__init__(
11101117
eps=eps, n_alphas=n_alphas, alphas=alphas,
11111118
fit_intercept=fit_intercept, normalize=normalize,
11121119
precompute=precompute, max_iter=max_iter, tol=tol, copy_X=copy_X,
1113-
cv=cv, verbose=verbose, positive=positive)
1120+
cv=cv, verbose=verbose, n_jobs=n_jobs, positive=positive)
11141121

11151122

11161123
class ElasticNetCV(LinearModelCV, RegressorMixin):

sklearn/linear_model/tests/test_coordinate_descent.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ def test_lasso_cv_positive_constraint():
184184
max_iter = 500
185185

186186
# Ensure the unconstrained fit has a negative coefficient
187-
clf_unconstrained = LassoCV(n_alphas=3, eps=1e-1, max_iter=max_iter, cv=2)
187+
clf_unconstrained = LassoCV(n_alphas=3, eps=1e-1, max_iter=max_iter, cv=2,
188+
n_jobs=1)
188189
clf_unconstrained.fit(X, y)
189190
assert_true(min(clf_unconstrained.coef_) < 0)
190191

191192
# On same data, constrained fit has non-negative coefficients
192193
clf_constrained = LassoCV(n_alphas=3, eps=1e-1, max_iter=max_iter,
193-
positive=True, cv=2)
194+
positive=True, cv=2, n_jobs=1)
194195
clf_constrained.fit(X, y)
195196
assert_true(min(clf_constrained.coef_) >= 0)
196197

@@ -322,13 +323,13 @@ def test_enet_cv_positive_constraint():
322323

323324
# Ensure the unconstrained fit has a negative coefficient
324325
enetcv_unconstrained = ElasticNetCV(n_alphas=3, eps=1e-1, max_iter=max_iter,
325-
cv=2)
326+
cv=2, n_jobs=1)
326327
enetcv_unconstrained.fit(X, y)
327328
assert_true(min(enetcv_unconstrained.coef_) < 0)
328329

329330
# On same data, constrained fit has non-negative coefficients
330331
enetcv_constrained = ElasticNetCV(n_alphas=3, eps=1e-1, max_iter=max_iter,
331-
cv=2, positive=True)
332+
cv=2, positive=True, n_jobs=1)
332333
enetcv_constrained.fit(X, y)
333334
assert_true(min(enetcv_constrained.coef_) >= 0)
334335

0 commit comments

Comments
 (0)
0