Skip to content

Commit ff8b12d

Browse files
committed
Merge branch 'pr/3247'
2 parents e4b2d96 + dcd5da3 commit ff8b12d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

doc/whats_new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ Changelog
159159
:class:`ElasticNetCV <linear_model.ElasticNetCV>`.
160160
By Brian Wignall and `Alexandre Gramfort`_.
161161

162+
- Fixed a bug in :class:`LassoCV <linear_model.LassoCV>` and
163+
:class:`ElasticNetCV <linear_model.ElasticNetCV>`: they would not
164+
pre-compute the Gram matrix with ``precompute=True`` or
165+
``precompute="auto"`` and ``n_samples > n_features``. By `Manoj Kumar`_.
166+
162167
- Fixed a race condition in parallel processing with
163168
``pre_dispatch != "all"`` (for instance in ``cross_val_score``).
164169
By `Olivier Grisel`_.

sklearn/linear_model/coordinate_descent.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,19 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
467467
coef_, l1_reg, l2_reg, X.data, X.indices,
468468
X.indptr, y, X_sparse_scaling,
469469
max_iter, tol, positive)
470-
elif not multi_output:
470+
elif multi_output:
471+
model = cd_fast.enet_coordinate_descent_multi_task(
472+
coef_, l1_reg, l2_reg, X, y, max_iter, tol)
473+
elif isinstance(precompute, np.ndarray):
474+
model = cd_fast.enet_coordinate_descent_gram(
475+
coef_, l1_reg, l2_reg, precompute, Xy, y, max_iter,
476+
tol, positive)
477+
elif precompute is False:
471478
model = cd_fast.enet_coordinate_descent(
472479
coef_, l1_reg, l2_reg, X, y, max_iter, tol, positive)
473480
else:
474-
model = cd_fast.enet_coordinate_descent_multi_task(
475-
coef_, l1_reg, l2_reg, X, y, max_iter, tol)
481+
raise ValueError("Precompute should be one of True, False, "
482+
"'auto' or array-like")
476483
coef_, dual_gap_, eps_ = model
477484
coefs[..., i] = coef_
478485
dual_gaps[i] = dual_gap_

sklearn/linear_model/tests/test_coordinate_descent.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ def test_sparse_input_dtype_enet_and_lassocv():
460460
assert_almost_equal(clf.coef_, clf1.coef_, decimal=6)
461461

462462

463+
def test_precompute_invalid_argument():
464+
X, y, _, _ = build_dataset()
465+
for clf in [ElasticNetCV(precompute="invalid"),
466+
LassoCV(precompute="invalid")]:
467+
assert_raises(ValueError, clf.fit, X, y)
468+
469+
463470
if __name__ == '__main__':
464471
import nose
465472
nose.runmodule()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy