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

FEA Add Nonnegative LinearRegression #17578

Merged
merged 50 commits into from Aug 6, 2020

Conversation

cmarmo
Copy link
Member

@cmarmo cmarmo commented Jun 12, 2020

Reference Issues/PRs

Fixes #8191. Resolves #11076, resolve #8428

What does this implement/fix? Explain your changes.

Adds parameters (positive and maxiter) to
LinearRegression consistent with Lasso and ElasticNet.

Any other comments?

#11076 was already approved by @TomDLT , I think I have addressed @rth comments.

Still missing

  • User Guide entry
  • Example
  • what's new

jknox13 and others added 9 commits May 7, 2018 17:12
…ugh `positive` parameter.

Similar to PR scikit-learn#8428, but adds parameters (`positive` and `max_iter`) to
`LinearRegression` consistent with `Lasso` and `ElasticNet`. Uses
`scipy.optimize.nnls` under the hood.

**note** `scipy.optimize.nnls` cannot accept a sparse matrix for `X` or
`y`. Passing sparse `X` throws error through `check_X_y`.
Remove `max_iter` parameter since `scipy.optimize.nnls` does not return `n_iter`.
Remove `_residues` attribute and unnecessary `np.ravel()`.
Copy link
Member

@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my previous comments:

This needs to appear in the user guide. Maybe also add an example, as here?
You will also need to add a mention in doc/whats_new/v0.24.rst.

sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Show resolved Hide resolved
@cmarmo cmarmo changed the title [MRG] Nonnegative LinearRegression through positive parameter. [WIP] Nonnegative LinearRegression through positive parameter. Jun 14, 2020
@cmarmo cmarmo changed the title [WIP] Nonnegative LinearRegression through positive parameter. [MRG] Nonnegative LinearRegression through positive parameter. Jun 15, 2020
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @cmarmo , mostly looks good

I think we could also have a test showing that we get different results when positive is True vs False

sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
doc/modules/linear_model.rst Outdated Show resolved Hide resolved
doc/modules/linear_model.rst Outdated Show resolved Hide resolved
examples/linear_model/plot_nnls.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
cmarmo and others added 4 commits June 15, 2020 13:52
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/_base.py Outdated Show resolved Hide resolved
doc/modules/linear_model.rst Outdated Show resolved Hide resolved
doc/modules/linear_model.rst Outdated Show resolved Hide resolved
examples/linear_model/plot_nnls.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cmarmo , made another pass but mostly looks good

examples/linear_model/plot_nnls.py Outdated Show resolved Hide resolved
doc/modules/linear_model.rst Outdated Show resolved Hide resolved
@cmarmo cmarmo requested a review from jnothman August 1, 2020 13:21
Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind a test showing positive=False/True makes no difference if positive=False already gets all non-negative coefficients.

But LGTM.

@cmarmo
Copy link
Member Author

cmarmo commented Aug 3, 2020

@jnothman, I have added the test.
Perhaps, @TomDLT or @NicolasHug have some time to check again? Thanks!

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cmarmo , minor comments but LGTM

examples/linear_model/plot_nnls.py Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
sklearn/linear_model/tests/test_base.py Outdated Show resolved Hide resolved
@NicolasHug NicolasHug changed the title [MRG] Nonnegative LinearRegression through positive parameter. FEA Add Nonnegative LinearRegression Aug 6, 2020
@NicolasHug NicolasHug merged commit 075d424 into scikit-learn:master Aug 6, 2020
7 checks passed
@cmarmo cmarmo deleted the LinearRegression_nnls_feature branch August 6, 2020 13:53
jayzed82 pushed a commit to jayzed82/scikit-learn that referenced this pull request Oct 22, 2020
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Joseph Knox <jknox13@uw.edu>
Co-authored-by: Joseph Knox <joseph.edward.knox@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-negative least square estimator
5 participants