FIX: make LinearRegression perfectly consistent across sparse or dense#13279
Merged
GaelVaroquaux merged 3 commits intoscikit-learn:masterfrom Feb 27, 2019
Merged
Conversation
glemaitre
requested changes
Feb 26, 2019
Member
glemaitre
left a comment
There was a problem hiding this 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_) |
Member
There was a problem hiding this comment.
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_) |
Member
There was a problem hiding this comment.
Suggested change
| assert_almost_equal(clf_dense.intercept_, clf_sparse.intercept_) | |
| assert clf_dense.intercept_ == pytest.approx(clf_sparse.intercept_) |
glemaitre
approved these changes
Feb 26, 2019
jnothman
reviewed
Feb 26, 2019
doc/whats_new/v0.21.rst
Outdated
| :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 |
Member
There was a problem hiding this comment.
I think this is missing mention of sparse/dense
sklearn/linear_model/base.py
Outdated
| 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) |
Member
|
|
|
|
||
| X_centered = sparse.linalg.LinearOperator(shape=X.shape, | ||
| matvec=matvec, | ||
| rmatvec=rmatvec) |
GaelVaroquaux
approved these changes
Feb 27, 2019
Member
GaelVaroquaux
left a comment
There was a problem hiding this comment.
Beautiful solution. +1 for merge.
Merging.
wdevazelhes
pushed a commit
to wdevazelhes/scikit-learn
that referenced
this pull request
Feb 27, 2019
…e the fit_intercept=False that should not be needed since scikit-learn#13279 is merged
Member
|
When 0-indented you require two blank lines, but elsewhere one.
|
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
scikit-learn#13279) * FIX : make LinearRegression perfectly consistent across sparse or dense * comments * review
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
… or dense (scikit-learn#13279)" This reverts commit 41f106c.
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
… or dense (scikit-learn#13279)" This reverts commit 41f106c.
koenvandevelde
pushed a commit
to koenvandevelde/scikit-learn
that referenced
this pull request
Jul 12, 2019
scikit-learn#13279) * FIX : make LinearRegression perfectly consistent across sparse or dense * comments * review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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