Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save avidale/6668635c318aceebe0142de013a4cf77 to your computer and use it in GitHub Desktop.
Save avidale/6668635c318aceebe0142de013a4cf77 to your computer and use it in GitHub Desktop.
inequality constraints in linear regression.ipynb
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@neerjachandra05
Copy link

Hi, how to put both constraints together, min beta value should be 1 and sum of all the betas should be equal or less than a particular no

@jfrasco
Copy link

jfrasco commented Sep 30, 2020

Hi, how to put both constraints together, min beta value should be 1 and sum of all the betas should be equal or less than a particular no

See my example above. -np.identity provides a single 1 for each beta under A, and you will then include the corresponding minimum value in B.

@neerjachandra05
Copy link

Its not working.
I am putting 2 conditions together:

  1. min beta value - 1
  2. sum of all beta <= a no

@jfrasco
Copy link

jfrasco commented Sep 30, 2020

Please paste your code.

@neerjachandra05
Copy link

Can I also make intercept positive. if yes, please let me know how? I am using the same code, just making min_coef = 1

@jpatria
Copy link

jpatria commented Nov 3, 2020

@avidale how is the coordinate descent computing the constraints? For example, if I used an interior point solver, it creates a barrier function for inequalities and then a newton line search is used.

EDIT: And what do you mean by "recalculating constraints for every coefficient on each step"?

@ywu-stats
Copy link

Thank you very much for sharing. This is what I'm looking for. Is there a way to just constrain specific subset of features and leave everything else as is?

@handelay
Copy link

Brilliant solution and well explained. I'm late to the party here but how would one modify this to use weighted-least-squares with constraints?

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