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

Intro to Telegraf
Intro to TelegrafIntro to Telegraf
Intro to Telegraf
InfluxData
 
Open ebs 101
Open ebs 101Open ebs 101
Open ebs 101
LibbySchulze
 
USENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsUSENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame Graphs
Brendan Gregg
 
10 reasons why to choose Pure Storage
10 reasons why to choose Pure Storage10 reasons why to choose Pure Storage
10 reasons why to choose Pure Storage
MarketingArrowECS_CZ
 
New Relic
New RelicNew Relic
New Relic
Gene Chuang
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
Brendan Gregg
 
Six Signs You Need Platform Engineering
Six Signs You Need Platform EngineeringSix Signs You Need Platform Engineering
Six Signs You Need Platform Engineering
Weaveworks
 
Introduction to eBPF
Introduction to eBPFIntroduction to eBPF
Introduction to eBPF
RogerColl2
 
Grafana.pptx
Grafana.pptxGrafana.pptx
Grafana.pptx
Bhushan Rane
 
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
Tokuhiro Matsuno
 
Successfully Implementing DEV-SEC-OPS in the Cloud
Successfully Implementing DEV-SEC-OPS in the CloudSuccessfully Implementing DEV-SEC-OPS in the Cloud
Successfully Implementing DEV-SEC-OPS in the Cloud
Amazon Web Services
 
Real-time Hadoop: The Ideal Messaging System for Hadoop
Real-time Hadoop: The Ideal Messaging System for Hadoop Real-time Hadoop: The Ideal Messaging System for Hadoop
Real-time Hadoop: The Ideal Messaging System for Hadoop
DataWorks Summit/Hadoop Summit
 
Lifecycle of a pod
Lifecycle of a podLifecycle of a pod
Lifecycle of a pod
Harshal Shah
 
Network Reliability Engineering and DevNetOps - Presented at ONS March 2018
Network Reliability Engineering and DevNetOps - Presented at ONS March 2018Network Reliability Engineering and DevNetOps - Presented at ONS March 2018
Network Reliability Engineering and DevNetOps - Presented at ONS March 2018
James Kelly
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux Kernel
Thomas Graf
 
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Edureka!
 
Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...
Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...
Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...
Roberto Pérez Alcolea
 
Radical Speed for SQL Queries on Databricks: Photon Under the Hood
Radical Speed for SQL Queries on Databricks: Photon Under the HoodRadical Speed for SQL Queries on Databricks: Photon Under the Hood
Radical Speed for SQL Queries on Databricks: Photon Under the Hood
Databricks
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
ScyllaDB
 
CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016] CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016]
IO Visor Project
 

What's hot (20)

Intro to Telegraf
Intro to TelegrafIntro to Telegraf
Intro to Telegraf
 
Open ebs 101
Open ebs 101Open ebs 101
Open ebs 101
 
USENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsUSENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame Graphs
 
10 reasons why to choose Pure Storage
10 reasons why to choose Pure Storage10 reasons why to choose Pure Storage
10 reasons why to choose Pure Storage
 
New Relic
New RelicNew Relic
New Relic
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
 
Six Signs You Need Platform Engineering
Six Signs You Need Platform EngineeringSix Signs You Need Platform Engineering
Six Signs You Need Platform Engineering
 
Introduction to eBPF
Introduction to eBPFIntroduction to eBPF
Introduction to eBPF
 
Grafana.pptx
Grafana.pptxGrafana.pptx
Grafana.pptx
 
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
 
Successfully Implementing DEV-SEC-OPS in the Cloud
Successfully Implementing DEV-SEC-OPS in the CloudSuccessfully Implementing DEV-SEC-OPS in the Cloud
Successfully Implementing DEV-SEC-OPS in the Cloud
 
Real-time Hadoop: The Ideal Messaging System for Hadoop
Real-time Hadoop: The Ideal Messaging System for Hadoop Real-time Hadoop: The Ideal Messaging System for Hadoop
Real-time Hadoop: The Ideal Messaging System for Hadoop
 
Lifecycle of a pod
Lifecycle of a podLifecycle of a pod
Lifecycle of a pod
 
Network Reliability Engineering and DevNetOps - Presented at ONS March 2018
Network Reliability Engineering and DevNetOps - Presented at ONS March 2018Network Reliability Engineering and DevNetOps - Presented at ONS March 2018
Network Reliability Engineering and DevNetOps - Presented at ONS March 2018
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux Kernel
 
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
Apache Spark Tutorial | Spark Tutorial for Beginners | Apache Spark Training ...
 
Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...
Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...
Escaping Dependency Hell: A deep dive into Gradle's dependency management fea...
 
Radical Speed for SQL Queries on Databricks: Photon Under the Hood
Radical Speed for SQL Queries on Databricks: Photon Under the HoodRadical Speed for SQL Queries on Databricks: Photon Under the Hood
Radical Speed for SQL Queries on Databricks: Photon Under the Hood
 
Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
 
CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016] CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016]
 

Similar to Using trained machine learning predictors in Gurobi

Callgraph analysis
Callgraph analysisCallgraph analysis
Callgraph analysis
Roberto Agostino Vitillo
 
Kaggle nlp approaches
Kaggle nlp approachesKaggle nlp approaches
Kaggle nlp approaches
prabu palanisamy
 
AMGLAB A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODS
AMGLAB  A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODSAMGLAB  A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODS
AMGLAB A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODS
Yolanda Ivey
 
SigOpt for Machine Learning and AI
SigOpt for Machine Learning and AISigOpt for Machine Learning and AI
SigOpt for Machine Learning and AI
SigOpt
 
QuantYOLOModels.pdf
QuantYOLOModels.pdfQuantYOLOModels.pdf
QuantYOLOModels.pdf
Degirum, Corp.
 
Parallel Artificial Bee Colony Algorithm
Parallel Artificial Bee Colony AlgorithmParallel Artificial Bee Colony Algorithm
Parallel Artificial Bee Colony Algorithm
Sameer Raghuram
 
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
mfrancis
 
Post compiler software optimization for reducing energy
Post compiler software optimization for reducing energyPost compiler software optimization for reducing energy
Post compiler software optimization for reducing energy
Abhishek Abhyankar
 
Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big Data
Scott Seighman
 
LCU14 303- Toolchain Collaboration
LCU14 303- Toolchain CollaborationLCU14 303- Toolchain Collaboration
LCU14 303- Toolchain Collaboration
Linaro
 
AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...
Institute of Contemporary Sciences
 
Sprint 44 review
Sprint 44 reviewSprint 44 review
Sprint 44 review
ManageIQ
 
Scaling machinelearning as a service at uber li Erran li - 2016
Scaling machinelearning as a service at uber li Erran li - 2016Scaling machinelearning as a service at uber li Erran li - 2016
Scaling machinelearning as a service at uber li Erran li - 2016
Karthik Murugesan
 
Scaling machine learning as a service at Uber — Li Erran Li at #papis2016
Scaling machine learning as a service at Uber — Li Erran Li at #papis2016Scaling machine learning as a service at Uber — Li Erran Li at #papis2016
Scaling machine learning as a service at Uber — Li Erran Li at #papis2016
PAPIs.io
 
Automatic machine learning (AutoML) 101
Automatic machine learning (AutoML) 101Automatic machine learning (AutoML) 101
Automatic machine learning (AutoML) 101
QuantUniversity
 
SigOpt for Hedge Funds
SigOpt for Hedge FundsSigOpt for Hedge Funds
SigOpt for Hedge Funds
SigOpt
 
Scaling Ride-Hailing with Machine Learning on MLflow
Scaling Ride-Hailing with Machine Learning on MLflowScaling Ride-Hailing with Machine Learning on MLflow
Scaling Ride-Hailing with Machine Learning on MLflow
Databricks
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen
Steve Feldman
 
Automating a PostgreSQL High Availability Architecture with Ansible
Automating a PostgreSQL High Availability Architecture with AnsibleAutomating a PostgreSQL High Availability Architecture with Ansible
Automating a PostgreSQL High Availability Architecture with Ansible
EDB
 
Spark Summit EU talk by Josef Habdank
Spark Summit EU talk by Josef HabdankSpark Summit EU talk by Josef Habdank
Spark Summit EU talk by Josef Habdank
Spark Summit
 

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

Callgraph analysis
Callgraph analysisCallgraph analysis
Callgraph analysis
 
Kaggle nlp approaches
Kaggle nlp approachesKaggle nlp approaches
Kaggle nlp approaches
 
AMGLAB A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODS
AMGLAB  A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODSAMGLAB  A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODS
AMGLAB A COMMUNITY PROBLEM SOLVING ENVIRONMENT FOR ALGEBRAIC MULTIGRID METHODS
 
SigOpt for Machine Learning and AI
SigOpt for Machine Learning and AISigOpt for Machine Learning and AI
SigOpt for Machine Learning and AI
 
QuantYOLOModels.pdf
QuantYOLOModels.pdfQuantYOLOModels.pdf
QuantYOLOModels.pdf
 
Parallel Artificial Bee Colony Algorithm
Parallel Artificial Bee Colony AlgorithmParallel Artificial Bee Colony Algorithm
Parallel Artificial Bee Colony Algorithm
 
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
 
Post compiler software optimization for reducing energy
Post compiler software optimization for reducing energyPost compiler software optimization for reducing energy
Post compiler software optimization for reducing energy
 
Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big Data
 
LCU14 303- Toolchain Collaboration
LCU14 303- Toolchain CollaborationLCU14 303- Toolchain Collaboration
LCU14 303- Toolchain Collaboration
 
AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...AutoML for user segmentation: how to match millions of users with hundreds of...
AutoML for user segmentation: how to match millions of users with hundreds of...
 
Sprint 44 review
Sprint 44 reviewSprint 44 review
Sprint 44 review
 
Scaling machinelearning as a service at uber li Erran li - 2016
Scaling machinelearning as a service at uber li Erran li - 2016Scaling machinelearning as a service at uber li Erran li - 2016
Scaling machinelearning as a service at uber li Erran li - 2016
 
Scaling machine learning as a service at Uber — Li Erran Li at #papis2016
Scaling machine learning as a service at Uber — Li Erran Li at #papis2016Scaling machine learning as a service at Uber — Li Erran Li at #papis2016
Scaling machine learning as a service at Uber — Li Erran Li at #papis2016
 
Automatic machine learning (AutoML) 101
Automatic machine learning (AutoML) 101Automatic machine learning (AutoML) 101
Automatic machine learning (AutoML) 101
 
SigOpt for Hedge Funds
SigOpt for Hedge FundsSigOpt for Hedge Funds
SigOpt for Hedge Funds
 
Scaling Ride-Hailing with Machine Learning on MLflow
Scaling Ride-Hailing with Machine Learning on MLflowScaling Ride-Hailing with Machine Learning on MLflow
Scaling Ride-Hailing with Machine Learning on MLflow
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen
 
Automating a PostgreSQL High Availability Architecture with Ansible
Automating a PostgreSQL High Availability Architecture with AnsibleAutomating a PostgreSQL High Availability Architecture with Ansible
Automating a PostgreSQL High Availability Architecture with Ansible
 
Spark Summit EU talk by Josef Habdank
Spark Summit EU talk by Josef HabdankSpark Summit EU talk by Josef Habdank
Spark Summit EU talk by Josef Habdank
 

Recently uploaded

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 

Recently uploaded (20)

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 

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 xavier.nodet@gurobi.com Thank You https://bit.ly/xnodet-slides