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 8, 2018
…e` parameter.

Similar to PR #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

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
sklearn/linear_model/_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

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 Jun 15, 2020
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

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 Aug 1, 2020
Copy link
Member

@jnothman jnothman left a comment

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 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

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
21 checks passed
21 checks passed
@lgtm-com
LGTM analysis: C/C++ No code changes detected
Details
@lgtm-com
LGTM analysis: JavaScript No code changes detected
Details
@lgtm-com
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
@circleci-artifacts-redirector
ci/circleci: doc artifact Link to 0/doc/_changed.html
Details
ci/circleci: doc-min-dependencies Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
@codecov
codecov/patch 100.00% of diff hit (target 98.09%)
Details
@codecov
codecov/project 98.09% (+0.00%) compared to febdd19
Details
@azure-pipelines
scikit-learn.scikit-learn Build #20200806.16 succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linting) Linting succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux py36_conda_openblas) Linux py36_conda_openblas succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux py36_ubuntu_atlas) Linux py36_ubuntu_atlas succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux pylatest_pip_openblas_pandas) Linux pylatest_pip_openblas_pandas succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux32 py36_ubuntu_atlas_32bit) Linux32 py36_ubuntu_atlas_32bit succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux_Runs pylatest_conda_mkl) Linux_Runs pylatest_conda_mkl succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Windows py36_pip_openblas_32bit) Windows py36_pip_openblas_32bit succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Windows py37_conda_mkl) Windows py37_conda_mkl succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (macOS pylatest_conda_mkl) macOS pylatest_conda_mkl succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (macOS pylatest_conda_mkl_no_openmp) macOS pylatest_conda_mkl_no_openmp succeeded
Details
@cmarmo cmarmo deleted the cmarmo:LinearRegression_nnls_feature branch Aug 6, 2020
jayzed82 added 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
Linked issues

Successfully merging this pull request may close these issues.

5 participants