add_predictor_constr in Gurobi modeling
AnsweredHi everyone,
I'm currently working on modifying an existing notebook titled "Part Two: Avocado Pricing and Supply Using Mathematical Optimization" available at https://github.com/Gurobi/modeling-examples/blob/master/price_optimization/price_optimization_gurobiML_gcl.ipynb.
My objective is to apply logarithmic transformations to the price and units_sold variables, but I'm facing an issue when trying to use the add_predictor_constr function. Unfortunately, I'm not able to figure out what the issue is, so I would greatly appreciate any assistance or suggestions on how to resolve this issue.
This is the link to my code https://github.com/Florenciavidal/TID/blob/main/log_transform3ipynb.ipynb
Thank you in advance for your help!
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-664-dfaa36de4a08> in <cell line: 1>() ----> 1 pred_constr = add_predictor_constr(m, reg, m_feats, d) 2 pred_constr.print_stats()
13 frames
/usr/local/lib/python3.10/dist-packages/gurobi_ml/sklearn/column_transformer.py in _mip_model(self, **kwargs) 77 if name in transformers: 78 trans_constr = transformers[name](self._gp_model, trans, data) ---> 79 transformed.append(trans_constr.output.tolist()) 80 else: 81 transformed.append(trans.transform(_input.loc[:, cols]))
UnboundLocalError: local variable 'trans_constr' referenced before assignment
-
Official comment
Hi Florencia,
The issue is that there is no implementation for adding the logarithmic transformation in Gurobi ML. Since the transformation is applied to Gurobi variables in the model, one would need to implement a class that performs it.
Then the error was not very graceful that I will fix.
If you really want to use a logarithmic transformer you would need to implement a small class similar to the ones in https://github.com/Gurobi/gurobi-machinelearning/blob/main/src/gurobi_ml/sklearn/preprocessing.py.
I hope this helps. Best regards,
Pierre
-
Hi Florencia,
I suspect this may be a bug in gurobi-machinelearning.
I have created a Github Issue for it.
- Riley
0
Please sign in to leave a comment.
Comments
2 comments