Add positive argument to Ridge regression
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d start with a LinearOperator and have dense and sparse support with a single minimal implementation.
@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
andLinearOperator
, so sparse input is accepted even ifpositive=True
. I needed to add new solver as"trf"
when usinglsq_linear
.Would you please check my implementation and whether it satisfies your requirement? Thank you!