Skip to content
Advertisement

Absurd solution using gurobi python in regression

So I am new to gurobi and I decided to start working with it on a well known problem as regression. I found this official notebook, where an L0 penalized regression model was solved and I took just the part of the regression model out of it. However, when I solve this problem in gurobi, I get a really strange solution, totally different from the actual correct regression solution.

The code I am running is:

JavaScript

The solution provided by this code is

JavaScript

While the true linear regression solution should be

JavaScript

That yields,

JavaScript

So gurobi solution is completely different. Any guess / suggestion on whats happening? Am I doing anything wrong here?

PD: I know that this problem can be solved using other packages, or even other optimization frameworks, but I am specially interested in solving it in gurobi python, since I want to start using gurobi in some more complex problems.

Advertisement

Answer

The wrong result is due to your decision variables. Since Gurobi assumes the lower bound 0 for all variables by default, you need to explicitly set the lower bound:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement