cog-imperial / OMLT

Represent trained machine learning models as Pyomo optimization formulations
Other
257 stars 56 forks source link

Solver gives wrong value for sklearn-inputs #98

Closed viggotw closed 1 year ago

viggotw commented 1 year ago

Hi, I tried making a simple notebook that optimizes the output of a single-input single-output sklearn gradient boosting model. The output-varieble seems to be ok, but the input variable (decision variable) is not. I've tested it with IPOPT and CBC. I am running this on Linux in Github Codespaces.

image image

It's hard to boil down my code to an MRE, so I've attached the full notebook. It is not that big.

OMLT with sklearn.zip

ThebTron commented 1 year ago

Hi viggotw,

Thanks a lot for raising this issue! Given that the GBT model uses discrete binary variables, I wouldn't expect IPOPT to return the right result. If you look at the output log in your notebook, it says: "Warning: Treating 90 binary and 0 integer variables as continuous.". That means that IPOPT is solving a continuous version of the problem. However, the CBC solve should work and I'll have a look at this in the next days. I hope I can get to this either this week or next week.

ThebTron commented 1 year ago

Hi viggotw,

I've had a look at this and fixed it! There are a few problems with the notebook and I can see how the OMLT interface is a bit confusing here. I'll address the issues with the team and we'll work on making it more intuitive.

In the meantime, these are the steps I took to fix the notebook:

  1. When defining initial_type you have to set dimension to one given that you're solving a 1-dimensional problem
  2. You'll also have to provide bounds when defining GradientBoostedTreeModel so OMLT can link the block inputs to the tree splits

Running the fixed notebook with cbc will give you the correct solution and also the correct objective after adding the mean of y given that we're using sklearn (see #80). I attached the fixed notebook here. As mentioned in the previous post, ipopt is not suitable here because you're trying to solve a discrete problem.

Please let me know if you have any other issues and thanks a lot for using the tool! image

EDIT: Had a small bug in my notebook, now everything should work fine!

tsaycal commented 1 year ago

This issue seems resolved, so I am closing it now.

Thanks @viggotw for the question and @ThebTron for the work on this.