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

FIX: make LinearRegression perfectly consistent across sparse or dense #13279

Merged

Conversation

5 participants
@agramfort
Copy link
Member

commented Feb 26, 2019

due to non centering of X when sparse, LinearRegression has never been 100% the same as the dense solver. This now fixes this.

cc @amueller

@agramfort agramfort added this to In progress in Sprint Paris 2019 Feb 26, 2019

@glemaitre
Copy link
Contributor

left a comment

You probably want to add an entry in what's new

clf_dense.fit(X, y)
clf_sparse.fit(Xcsr, y)
assert_almost_equal(clf_dense.intercept_, clf_sparse.intercept_)
assert_array_almost_equal(clf_dense.coef_, clf_sparse.coef_)

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
assert_array_almost_equal(clf_dense.coef_, clf_sparse.coef_)
assert_allclose(clf_dense.coef_, clf_sparse.coef_)
clf_sparse = LinearRegression(**params)
clf_dense.fit(X, y)
clf_sparse.fit(Xcsr, y)
assert_almost_equal(clf_dense.intercept_, clf_sparse.intercept_)

This comment has been minimized.

Copy link
@glemaitre

glemaitre Feb 26, 2019

Contributor
Suggested change
assert_almost_equal(clf_dense.intercept_, clf_sparse.intercept_)
assert clf_dense.intercept_ == pytest.approx(clf_sparse.intercept_)

@glemaitre glemaitre changed the title FIX : make LinearRegression perfectly consistent across sparse or dense FIX: make LinearRegression perfectly consistent across sparse or dense Feb 26, 2019

@glemaitre glemaitre self-requested a review Feb 26, 2019

@jnothman
Copy link
Member

left a comment

Otherwise LGTM

@@ -174,6 +174,10 @@ Support for Python 3.4 and below has been officially dropped.
parameter value ``copy_X=True`` in ``fit``.
:issue:`12972` by :user:`Lucio Fernandez-Arjona <luk-f-a>`

- |Fix| Fixed a bug in :class:`linear_model.LinearRegression` that
was not returning the same coeffecient and intercepts with

This comment has been minimized.

Copy link
@jnothman

jnothman Feb 26, 2019

Member

I think this is missing mention of sparse/dense

def matvec(b):
return X.dot(b) - b.dot(X_offset_scale)
def rmatvec(b):
return X.T.dot(b) - (X_offset_scale) * np.sum(b)

This comment has been minimized.

Copy link
@jnothman

jnothman Feb 26, 2019

Member

redundant parentheses

Show resolved Hide resolved sklearn/linear_model/base.py
@glemaitre

This comment has been minimized.

Copy link
Contributor

commented Feb 26, 2019

We should almost have a common test. Wrong PR.

@agramfort agramfort moved this from In progress to Needs review in Sprint Paris 2019 Feb 27, 2019


X_centered = sparse.linalg.LinearOperator(shape=X.shape,
matvec=matvec,
rmatvec=rmatvec)

This comment has been minimized.

Copy link
@GaelVaroquaux

GaelVaroquaux Feb 27, 2019

Member

Very elegant!

@GaelVaroquaux
Copy link
Member

left a comment

Beautiful solution. +1 for merge.

Merging.

@GaelVaroquaux GaelVaroquaux merged commit 66899ed into scikit-learn:master Feb 27, 2019

11 checks passed

LGTM analysis: C/C++ No code changes detected
Details
LGTM analysis: JavaScript No code changes detected
Details
LGTM analysis: Python No new or fixed alerts
Details
ci/circleci: deploy Your tests passed on CircleCI!
Details
ci/circleci: doc Your tests passed on CircleCI!
Details
ci/circleci: doc-min-dependencies Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 92.49%)
Details
codecov/project 92.5% (+0.01%) compared to face9da
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

Sprint Paris 2019 automation moved this from Needs review to Done Feb 27, 2019

wdevazelhes added a commit to wdevazelhes/scikit-learn that referenced this pull request Feb 27, 2019

FIX: fix teh check that was making fail AffinityPropagation and remov…
…e the fit_intercept=False that should not be needed since scikit-learn#13279 is merged
@jnothman

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

Kiku-git added a commit to Kiku-git/scikit-learn that referenced this pull request Mar 4, 2019

FIX: make LinearRegression perfectly consistent across sparse or dense (
scikit-learn#13279)

* FIX : make LinearRegression perfectly consistent across sparse or dense

* comments

* review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.