0
$\begingroup$

I'm working on a regression problem where I want to use Lasso model. With the help of Lasso and LassoCV, we can provide different alpha values and get the best parameter and coefficients however I couldn't find option to set limit or direction for coefficients.

Ex. I have 3 independent variables I1, I2 and I3. I want my I1 and I2 coefficients to be in range(0 , +inf) and I3 in (-inf, 0). Can someone please guide how can I set this in python?

$\endgroup$

1 Answer 1

1
$\begingroup$

Scikit-learn (which I'm assuming you're using) does not allow you to constrain the coefficients in such a way (at most you can constrain them to all be positive with positive=True).

However you will find a custom estimator implementation which achieves what you're looking for here: https://stackoverflow.com/q/50410037/16779958.

$\endgroup$
1
  • $\begingroup$ The first paragraph can solve the specific example in the Question: negate the feature I3 and then add the positive=True parameter. $\endgroup$
    – Ben Reiniger
    Jun 22, 2022 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.