SlideShare a Scribd company logo
Xavier Nodet
Development Manager
February 2023
ROADEF
Gurobi
Machine Learning
Using trained machine learning predictors in Gurobi
© 2023 Gurobi Optimization, LLC. All Rights Reserved
Agenda
Motivating example
Optimizing avocado shipments and prices
Gurobi Machine Learning
An open-source Python package
Gurobi 10.0
Performance improvements for models with
ML predictor constraints
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 2
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 3
Optimizing avocado shipments and prices
Motivating example
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 3
• Selling avocados in the US
• Market is split in regions 𝑅
• Total supply 𝑆
• Maximize profit:
• (sales – shipping costs – unsold penalty)
with given
• shipping costs 𝑐! and waste penalty 𝑤
• We decide about the prices 𝑝!
• and estimate the demands d" from the prices
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 4
Motivating Example: Price Optimization
https://youtu.be/AJRP9pPBx6s
• Historical data of avocado sales from
Hass Avocado Board (HAB) available
on Kaggle and HAB website
• Features correlated to demand:
price, region, year, peak season
• Linear regression gives reasonably
good prediction of demand with those:
𝑑 = 𝑔(𝑝, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛)
• In the case of linear regression, 𝑔 is an
affine function
𝑑 = 𝜙# 𝑝, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 + 𝜙$
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 5
Motivating Example: Estimating Demand
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 6
Motivating Example: Retrieving ML results
coef_dict = model.fit().params.to_dict()
d = {r: (coef_dict['Intercept’] +
coef_dict['price’] * p[r] +
coef_dict['C(region)[T.%s]'%r] +
coef_dict['year_index’] * (year - 2015) +
coef_dict['peak’] * peak_or_not)
for r in R}
m.addConstrs((s[r] <= d[r] for r in R))
• Retrieve results from linear regression model
• Build linear expression defining expected demand from price
• Upper bound on sales is expected demand
• Indices
• r ∈ 𝑅, the set of regions
• Variables
• p" selling price per unit
• d" demand
• u total unsold products
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 7
Motivating Example: Optimization Model
max ∑! 𝑝! − 𝑐! 𝑑! − 𝑤 ∗ 𝑢 (maximize revenue)
𝑠. 𝑡.
∑! 𝑑! + 𝑢 = 𝑆 (allocate shipments)
𝑑! = 𝑔 𝑝!, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 for r ∈ 𝑅 (define demand with regression model)
• Indices
• r ∈ 𝑅, the set of regions
• Constants
• 𝑐! transportation costs
• 𝑤 penalty for waste
• 𝑆 total supply
• Year and season of interest
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 8
Motivating Example: What if?
max ∑! 𝑝! − 𝑐! 𝑑! − 𝑤 ∗ 𝑢 (maximize revenue)
𝑠. 𝑡.
∑! 𝑑! + 𝑢 = 𝑆 (allocate shipments)
𝑑! = 𝑔 𝑝!, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 for r ∈ 𝑅 (define demand with regression model)
• With 𝑔 an affine function, the resulting model is a non-convex QP
• Solved fast with Gurobi
• But what if we need a more accurate prediction with a more complex regression:
• Decision tree, Neural network, …
1. Simplify the process of importing a trained machine learning model built with a
popular ML package into an optimization model.
2. Improve algorithmic performance to enable the optimization model to explore a
sizable space of solutions that satisfy the relationships between variables captured
with the ML model.
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 9
Motivating Example: Goals
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 10
An open-source Python package
Gurobi Machine Learning
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 10
• Open source python package:
• https://github.com/Gurobi/gurobi-machinelearning
• https://gurobi-machinelearning.readthedocs.io/
• Apache License 2.0
• Initial release 1.0.0 last November
• Version 1.1.0 recently released
• Experimental package
• Not supported through usual Gurobi processes
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 11
Gurobi Machine Learning
• Linear/Logistic/PLS regression
• Decision trees
• Neural network with ReLU activation
• Random Forests
• Gradient Boosting
• Preprocessing:
• Simple scaling
• Polynomial features of degree 2
• Column transformers
• pipelines to combine them
• Dense layers
• ReLU layers
• Object Oriented, functional or
sequential
• Dense layers
• ReLU layers
• Only torch.nn.Sequential models
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 12
Known regression models
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 13
Example: Define and train ML model
...
lin_reg = make_pipeline(columntransformer, LinearRegression())
lin_reg.fit(X_train, y_train)
• Variables
• 𝑝! selling price per unit
• 𝑑! demand
• 𝑢 total unsold products
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 17
Example: Creating the variables
import gurobipy_pandas as gppd
data = pd.concat(...)
m = gp.Model("Avocado_Price_Allocation")
p = gppd.add_vars(m, data, lb=0.0, ub=2.0)
d = gppd.add_vars(m, data)
u = m.addVar()
m.setObjective(((p – c) * d).sum() - w * u, GRB.MAXIMIZE)
m.addConstr(d.sum() + u == S)
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 18
Example: Adding regression constraints
fixed = pd.DataFrame(
data={
"year": 2020,
"peak": 1,
"region": regions,
},
index=regions)
feats = pd.concat(
[fixed, p],
axis=1)
𝑑! = 𝑔 𝑝!, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 for r ∈ 𝑅.
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 19
Example: Adding Regression Constraints
from gurobi_ml import add_predictor_constr
pred_constr = add_predictor_constr(m, lin_reg, feats, d)
pred_constr.print_stats()
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 20
Example: Optimizing
m.Params.NonConvex = 2
m.optimize()
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 21
Example: Solution
• Function add_predictor_constr creates the formulation for regression
model and returns a modeling object.
• If input of add_predictor_constr has several rows, it introduces one sub-
model for each row
• Query statistics about modeling object, remove it, query solution after solve and
error in solutions.
• Models for logistic regression use a piecewise linear approximation and can have
modeling error (controlled by parameters).
• Models for decision tree can also introduce small errors at threshold values of
node splitting (can be controlled).
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 22
Remarks
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 23
Performance improvements for models with ML
predictor constraints
Gurobi 10.0
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 23
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 24
Gurobi 9.5 vs Gurobi 10.0
• 478 instances
• 10.000 seconds time limit
• Intel(R) Xeon(R) CPU E3-1240 CPUs, 4 cores, 4
threads
• Solved means 0.01% gap reached
• Models not solved by any version were
excluded
• Models incorporating Neural
Networks
• Performance gains come mostly
from Optimization Based Bound
Tightening (OBBT)
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 25
Conclusion
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 25
• Gurobi Machine Learning
https://github.com/Gurobi/gurobi-machinelearning
• This is experimental
• Input very welcome
• Performance for models with Neural Networks in
Gurobi 10
Dangers and Pitfalls
• ML models we can hope to handle is still limited (e.g. no categorical features)
• Methodological issues:
• How to decide which prediction model to use?
• How to make sure that optimization doesn’t misuse results of the predictor?
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 26
Conclusion
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 27
For more details…
https://www.gurobi.com/events/
using-trained-machine-learning-
predictors-in-gurobi
© 2023 Gurobi Optimization, LLC. All Rights Reserved | 28
For more information: gurobi.com
Xavier Nodet
Development Manager
xavier.nodet@gurobi.com
Thank You https://bit.ly/xnodet-slides

More Related Content

What's hot (20)

PDF
Etsy Activity Feeds Architecture
Dan McKinley
 
PDF
Using ClickHouse for Experimentation
Gleb Kanterov
 
PDF
High Performance Data Lake with Apache Hudi and Alluxio at T3Go
Alluxio, Inc.
 
PDF
XStream: stream processing platform at facebook
Aniket Mokashi
 
PDF
Introduction to Modern Data Virtualization (US)
Denodo
 
PPTX
How to boost your datamanagement with Dremio ?
Vincent Terrasi
 
PDF
Integration Patterns and Anti-Patterns for Microservices Architectures
Apcera
 
PPTX
A chart of the big data ecosystem
Matt Turck
 
PPTX
Big data - Cours d'introduction l Data-business
Vincent de Stoecklin
 
PDF
Scalable Monitoring Using Apache Spark and Friends with Utkarsh Bhatnagar
Databricks
 
PPTX
Ecosystème Big Data
Idriss22
 
PDF
Pinot: Enabling Real-time Analytics Applications @ LinkedIn's Scale
Seunghyun Lee
 
PDF
Troubleshooting sql server
Antonios Chatzipavlis
 
PDF
Traitement distribue en BIg Data - KAFKA Broker and Kafka Streams
ENSET, Université Hassan II Casablanca
 
PDF
An overview of Neo4j Internals
Tobias Lindaaker
 
PDF
Streaming with Oracle Data Integration
Michael Rainey
 
PPTX
Introduction to Dremio
Dremio Corporation
 
PPTX
CockroachDB
andrei moga
 
PDF
Spark SQL Deep Dive @ Melbourne Spark Meetup
Databricks
 
PDF
ClickHouse Keeper
Altinity Ltd
 
Etsy Activity Feeds Architecture
Dan McKinley
 
Using ClickHouse for Experimentation
Gleb Kanterov
 
High Performance Data Lake with Apache Hudi and Alluxio at T3Go
Alluxio, Inc.
 
XStream: stream processing platform at facebook
Aniket Mokashi
 
Introduction to Modern Data Virtualization (US)
Denodo
 
How to boost your datamanagement with Dremio ?
Vincent Terrasi
 
Integration Patterns and Anti-Patterns for Microservices Architectures
Apcera
 
A chart of the big data ecosystem
Matt Turck
 
Big data - Cours d'introduction l Data-business
Vincent de Stoecklin
 
Scalable Monitoring Using Apache Spark and Friends with Utkarsh Bhatnagar
Databricks
 
Ecosystème Big Data
Idriss22
 
Pinot: Enabling Real-time Analytics Applications @ LinkedIn's Scale
Seunghyun Lee
 
Troubleshooting sql server
Antonios Chatzipavlis
 
Traitement distribue en BIg Data - KAFKA Broker and Kafka Streams
ENSET, Université Hassan II Casablanca
 
An overview of Neo4j Internals
Tobias Lindaaker
 
Streaming with Oracle Data Integration
Michael Rainey
 
Introduction to Dremio
Dremio Corporation
 
CockroachDB
andrei moga
 
Spark SQL Deep Dive @ Melbourne Spark Meetup
Databricks
 
ClickHouse Keeper
Altinity Ltd
 

Similar to Using trained machine learning predictors in Gurobi (17)

PPTX
Packing Problems Using Gurobi
Terrance Smith
 
PDF
super-cheatsheet-artificial-intelligence.pdf
ssuser089265
 
PDF
AIRLINE FARE PRICE PREDICTION
IRJET Journal
 
PDF
Train, explain, acclaim. Build a good model in three steps
Przemek Biecek
 
DOCX
Linear programming wi̇th R
Dr. Volkan OBAN
 
PDF
Artificial Neuron Network-Based Prediction of Fuel Consumption in Antananarivo
IJAEMSJORNAL
 
PDF
Machine Learning... a piece of cake!
BeeBryte | Energy Intelligence & Automation
 
PDF
Automatic and Interpretable Machine Learning with H2O and LIME
Jo-fai Chow
 
PDF
Azure Machine Learning tutorial
Giacomo Lanciano
 
PPTX
Yuwu chen
Yuwu Chen
 
PPTX
Introduction to Price Optimisation
Ammar Mohemmed
 
DOCX
Linear Programming wi̇th R - Examples
Dr. Volkan OBAN
 
DOCX
R Machine Learning packages( generally used)
Dr. Volkan OBAN
 
PDF
Human-Centered Interpretable Machine Learning
Przemek Biecek
 
PPTX
construire modele machine_Learning.pptx
koooragoal20000
 
PPTX
Applied optimization in Matlab for Power System.pptx
HenryKim20273
 
PDF
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Aijun Zhang
 
Packing Problems Using Gurobi
Terrance Smith
 
super-cheatsheet-artificial-intelligence.pdf
ssuser089265
 
AIRLINE FARE PRICE PREDICTION
IRJET Journal
 
Train, explain, acclaim. Build a good model in three steps
Przemek Biecek
 
Linear programming wi̇th R
Dr. Volkan OBAN
 
Artificial Neuron Network-Based Prediction of Fuel Consumption in Antananarivo
IJAEMSJORNAL
 
Machine Learning... a piece of cake!
BeeBryte | Energy Intelligence & Automation
 
Automatic and Interpretable Machine Learning with H2O and LIME
Jo-fai Chow
 
Azure Machine Learning tutorial
Giacomo Lanciano
 
Yuwu chen
Yuwu Chen
 
Introduction to Price Optimisation
Ammar Mohemmed
 
Linear Programming wi̇th R - Examples
Dr. Volkan OBAN
 
R Machine Learning packages( generally used)
Dr. Volkan OBAN
 
Human-Centered Interpretable Machine Learning
Przemek Biecek
 
construire modele machine_Learning.pptx
koooragoal20000
 
Applied optimization in Matlab for Power System.pptx
HenryKim20273
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Aijun Zhang
 
Ad

Recently uploaded (20)

PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Import Data Form Excel to Tally Services
Tally xperts
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Ad

Using trained machine learning predictors in Gurobi

  • 1. Xavier Nodet Development Manager February 2023 ROADEF Gurobi Machine Learning Using trained machine learning predictors in Gurobi © 2023 Gurobi Optimization, LLC. All Rights Reserved
  • 2. Agenda Motivating example Optimizing avocado shipments and prices Gurobi Machine Learning An open-source Python package Gurobi 10.0 Performance improvements for models with ML predictor constraints © 2023 Gurobi Optimization, LLC. All Rights Reserved | 2
  • 3. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 3 Optimizing avocado shipments and prices Motivating example © 2023 Gurobi Optimization, LLC. All Rights Reserved | 3
  • 4. • Selling avocados in the US • Market is split in regions 𝑅 • Total supply 𝑆 • Maximize profit: • (sales – shipping costs – unsold penalty) with given • shipping costs 𝑐! and waste penalty 𝑤 • We decide about the prices 𝑝! • and estimate the demands d" from the prices © 2023 Gurobi Optimization, LLC. All Rights Reserved | 4 Motivating Example: Price Optimization https://youtu.be/AJRP9pPBx6s
  • 5. • Historical data of avocado sales from Hass Avocado Board (HAB) available on Kaggle and HAB website • Features correlated to demand: price, region, year, peak season • Linear regression gives reasonably good prediction of demand with those: 𝑑 = 𝑔(𝑝, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛) • In the case of linear regression, 𝑔 is an affine function 𝑑 = 𝜙# 𝑝, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 + 𝜙$ © 2023 Gurobi Optimization, LLC. All Rights Reserved | 5 Motivating Example: Estimating Demand
  • 6. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 6 Motivating Example: Retrieving ML results coef_dict = model.fit().params.to_dict() d = {r: (coef_dict['Intercept’] + coef_dict['price’] * p[r] + coef_dict['C(region)[T.%s]'%r] + coef_dict['year_index’] * (year - 2015) + coef_dict['peak’] * peak_or_not) for r in R} m.addConstrs((s[r] <= d[r] for r in R)) • Retrieve results from linear regression model • Build linear expression defining expected demand from price • Upper bound on sales is expected demand
  • 7. • Indices • r ∈ 𝑅, the set of regions • Variables • p" selling price per unit • d" demand • u total unsold products © 2023 Gurobi Optimization, LLC. All Rights Reserved | 7 Motivating Example: Optimization Model max ∑! 𝑝! − 𝑐! 𝑑! − 𝑤 ∗ 𝑢 (maximize revenue) 𝑠. 𝑡. ∑! 𝑑! + 𝑢 = 𝑆 (allocate shipments) 𝑑! = 𝑔 𝑝!, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 for r ∈ 𝑅 (define demand with regression model) • Indices • r ∈ 𝑅, the set of regions • Constants • 𝑐! transportation costs • 𝑤 penalty for waste • 𝑆 total supply • Year and season of interest
  • 8. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 8 Motivating Example: What if? max ∑! 𝑝! − 𝑐! 𝑑! − 𝑤 ∗ 𝑢 (maximize revenue) 𝑠. 𝑡. ∑! 𝑑! + 𝑢 = 𝑆 (allocate shipments) 𝑑! = 𝑔 𝑝!, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 for r ∈ 𝑅 (define demand with regression model) • With 𝑔 an affine function, the resulting model is a non-convex QP • Solved fast with Gurobi • But what if we need a more accurate prediction with a more complex regression: • Decision tree, Neural network, …
  • 9. 1. Simplify the process of importing a trained machine learning model built with a popular ML package into an optimization model. 2. Improve algorithmic performance to enable the optimization model to explore a sizable space of solutions that satisfy the relationships between variables captured with the ML model. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 9 Motivating Example: Goals
  • 10. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 10 An open-source Python package Gurobi Machine Learning © 2023 Gurobi Optimization, LLC. All Rights Reserved | 10
  • 11. • Open source python package: • https://github.com/Gurobi/gurobi-machinelearning • https://gurobi-machinelearning.readthedocs.io/ • Apache License 2.0 • Initial release 1.0.0 last November • Version 1.1.0 recently released • Experimental package • Not supported through usual Gurobi processes © 2023 Gurobi Optimization, LLC. All Rights Reserved | 11 Gurobi Machine Learning
  • 12. • Linear/Logistic/PLS regression • Decision trees • Neural network with ReLU activation • Random Forests • Gradient Boosting • Preprocessing: • Simple scaling • Polynomial features of degree 2 • Column transformers • pipelines to combine them • Dense layers • ReLU layers • Object Oriented, functional or sequential • Dense layers • ReLU layers • Only torch.nn.Sequential models © 2023 Gurobi Optimization, LLC. All Rights Reserved | 12 Known regression models
  • 13. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 13 Example: Define and train ML model ... lin_reg = make_pipeline(columntransformer, LinearRegression()) lin_reg.fit(X_train, y_train)
  • 14. • Variables • 𝑝! selling price per unit • 𝑑! demand • 𝑢 total unsold products © 2023 Gurobi Optimization, LLC. All Rights Reserved | 17 Example: Creating the variables import gurobipy_pandas as gppd data = pd.concat(...) m = gp.Model("Avocado_Price_Allocation") p = gppd.add_vars(m, data, lb=0.0, ub=2.0) d = gppd.add_vars(m, data) u = m.addVar() m.setObjective(((p – c) * d).sum() - w * u, GRB.MAXIMIZE) m.addConstr(d.sum() + u == S)
  • 15. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 18 Example: Adding regression constraints fixed = pd.DataFrame( data={ "year": 2020, "peak": 1, "region": regions, }, index=regions) feats = pd.concat( [fixed, p], axis=1) 𝑑! = 𝑔 𝑝!, 𝑟, 𝑦𝑒𝑎𝑟, 𝑠𝑒𝑎𝑠𝑜𝑛 for r ∈ 𝑅.
  • 16. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 19 Example: Adding Regression Constraints from gurobi_ml import add_predictor_constr pred_constr = add_predictor_constr(m, lin_reg, feats, d) pred_constr.print_stats()
  • 17. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 20 Example: Optimizing m.Params.NonConvex = 2 m.optimize()
  • 18. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 21 Example: Solution
  • 19. • Function add_predictor_constr creates the formulation for regression model and returns a modeling object. • If input of add_predictor_constr has several rows, it introduces one sub- model for each row • Query statistics about modeling object, remove it, query solution after solve and error in solutions. • Models for logistic regression use a piecewise linear approximation and can have modeling error (controlled by parameters). • Models for decision tree can also introduce small errors at threshold values of node splitting (can be controlled). © 2023 Gurobi Optimization, LLC. All Rights Reserved | 22 Remarks
  • 20. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 23 Performance improvements for models with ML predictor constraints Gurobi 10.0 © 2023 Gurobi Optimization, LLC. All Rights Reserved | 23
  • 21. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 24 Gurobi 9.5 vs Gurobi 10.0 • 478 instances • 10.000 seconds time limit • Intel(R) Xeon(R) CPU E3-1240 CPUs, 4 cores, 4 threads • Solved means 0.01% gap reached • Models not solved by any version were excluded • Models incorporating Neural Networks • Performance gains come mostly from Optimization Based Bound Tightening (OBBT)
  • 22. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 25 Conclusion © 2023 Gurobi Optimization, LLC. All Rights Reserved | 25
  • 23. • Gurobi Machine Learning https://github.com/Gurobi/gurobi-machinelearning • This is experimental • Input very welcome • Performance for models with Neural Networks in Gurobi 10 Dangers and Pitfalls • ML models we can hope to handle is still limited (e.g. no categorical features) • Methodological issues: • How to decide which prediction model to use? • How to make sure that optimization doesn’t misuse results of the predictor? © 2023 Gurobi Optimization, LLC. All Rights Reserved | 26 Conclusion
  • 24. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 27 For more details… https://www.gurobi.com/events/ using-trained-machine-learning- predictors-in-gurobi
  • 25. © 2023 Gurobi Optimization, LLC. All Rights Reserved | 28 For more information: gurobi.com Xavier Nodet Development Manager [email protected] Thank You https://bit.ly/xnodet-slides