Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG+1] Fixes #10571: Shape of coef_ wrong for linear_model.Lasso when using `fit_interce… #10687

Merged
merged 5 commits into from Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whats_new/v0.20.rst
Expand Up @@ -246,6 +246,10 @@ Classifiers and regressors
overridden when using parameter ``copy_X=True`` and ``check_input=False``.
:issue:`10581` by :user:`Yacine Mazari <ymazari>`.

- Fixed a bug in :class:`sklearn.linear_model.Lasso`
where the coefficient had wrong shape when ``fit_intercept=False``.
:issue:`10687` by :user:`Martin Hahn <martin-hahn>`.

Decomposition, manifold learning and clustering

- Fix for uninformative error in :class:`decomposition.IncrementalPCA`:
Expand Down
6 changes: 5 additions & 1 deletion sklearn/linear_model/coordinate_descent.py
Expand Up @@ -762,8 +762,12 @@ def fit(self, X, y, check_input=True):

if n_targets == 1:
self.n_iter_ = self.n_iter_[0]
self.coef_ = coef_[0]
self.dual_gap_ = dual_gaps_[0]
else:
self.coef_ = coef_
self.dual_gap_ = dual_gaps_

self.coef_, self.dual_gap_ = map(np.squeeze, [coef_, dual_gaps_])
self._set_intercept(X_offset, y_offset, X_scale)

# workaround since _set_intercept will cast self.coef_ into X.dtype
Expand Down
6 changes: 6 additions & 0 deletions sklearn/linear_model/tests/test_coordinate_descent.py
Expand Up @@ -803,3 +803,9 @@ def test_enet_l1_ratio():
est.fit(X, y[:, None])
est_desired.fit(X, y[:, None])
assert_array_almost_equal(est.coef_, est_desired.coef_, decimal=5)


def test_coef_shape_not_zero():
est_no_intercept = Lasso(fit_intercept=False)
est_no_intercept.fit(np.c_[np.ones(3)], np.ones(3))
assert est_no_intercept.coef_.shape == (1,)