Skip to content

Add positive argument to Ridge regression #19772

Closed

Description

@lorentzenchr

Describe the workflow you want to enable

I'd like to have

reg = Ridge(positive=True)
reg.fit(X, y)

print(reg.coef_)

and only get non-negative print results.
Adding positive to Ridge was proposed in #19615 (comment).

Describe your proposed solution

Either use scipy.optimize.nnls, which is used in LinearRegression, or scipy.optimize.lsq_linear, which has support for sparse input and LinearOperator.

Describe alternatives you've considered, if relevant

As the first step of lsq_linear is to solve the unconstrained least square problem, one might consider using the present ridge solvers for that and then call trf_linear or bvls.

Additional context

Linear models that already have a positive option are:

  • LinearRegression
  • ElasticNet
  • ElasticNetCV
  • Lasso
  • LassoCV
  • LassoLars
  • ...

Activity

  1. changed the title [-]ENH Add positive argument to Ridge regression[/-] [+]Add positive argument to Ridge regression[/+] on Mar 27, 2021
  2. added
    Moderate
    on Mar 27, 2021
  3. agramfort commented on Mar 31, 2021

    @agramfort
    Member

    yes scipy.optimize.lsq_linear seems a good fit but due to L2 reg either you assemble a (n_samples + n_features, n_features) dense matrix or you need to use LinearOperator. What do you have in mind @lorentzenchr ?

  4. lorentzenchr commented on Apr 1, 2021

    @lorentzenchr
    MemberAuthor

    I'd start with a LinearOperator and have dense and sparse support with a single minimal implementation.

  5. cesar-ca commented on Apr 23, 2021

    @cesar-ca

    Hey! I'd like to work on this!

  6. lorentzenchr commented on May 7, 2021

    @lorentzenchr
    MemberAuthor

    @cesar-ca Cool. Feel free to open a PR. But note that this is not the easiest issue to solve.

  7. lorentzenchr commented on May 25, 2021

    @lorentzenchr
    MemberAuthor

    @cesar-ca I don't see a pull request. Do you need help or did you decide not to persue?

  8. tnakae commented on Jun 9, 2021

    @tnakae
    Contributor

    @lorentzenchr
    I opened PR #20231 to add positive argument to Ridge.
    This feature is often needed in my job when I have to calculate positive economical impact.
    I implemented it because It seems that nobody has not implemented yet.

    Based on your idea, I used lsq_linear and LinearOperator, so sparse input is accepted even if positive=True.
    I needed to add new solver as "trf" when using lsq_linear.

    Would you please check my implementation and whether it satisfies your requirement?
    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ModerateNew Featurehelp wantedmodule:linear_model

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions