question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add positive argument to Ridge regression

See original GitHub issue

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 https://github.com/scikit-learn/scikit-learn/issues/19615#issuecomment-808112174.

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lorentzenchrcommented, Apr 1, 2021

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

0reactions
tnakaecommented, Jun 9, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Develop Ridge Regression Models in Python
Ridge Regression is an extension of linear regression that adds a ... can be configured via the “alpha” argument when defining the class....
Read more >
sklearn.linear_model.Ridge — scikit-learn 1.2.0 documentation
This model solves a regression model where the loss function is the linear least squares function and regularization is given by the l2-norm....
Read more >
Ridge Regression for Better Usage - Towards Data Science
The goal of this post is to let you better use ridge regression than just use what libraries provide. Then, “What is Ridge...
Read more >
Lecture notes on ridge regression - arXiv
This document is a collection of many well-known results on ridge regression. The current status of the document is 'work-in-progress' as it is ......
Read more >
How to perform non-negative ridge regression?
For the sake of argument I append this second solution too. I am not fully conversational in Python but essentially you can replicate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found