https://github.com/gurobi/gurobi-machinelearning
Formulate trained predictors in Gurobi models
https://github.com/gurobi/gurobi-machinelearning
gurobi machine-learning mathematical-optimization python
Last synced: about 1 year ago
JSON representation
Formulate trained predictors in Gurobi models
- Host: GitHub
- URL: https://github.com/gurobi/gurobi-machinelearning
- Owner: Gurobi
- License: apache-2.0
- Created: 2022-04-22T16:24:33.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-04T08:23:35.000Z (about 1 year ago)
- Last Synced: 2025-04-07T21:08:30.657Z (about 1 year ago)
- Topics: gurobi, machine-learning, mathematical-optimization, python
- Language: Python
- Homepage: https://gurobi-machinelearning.readthedocs.io/
- Size: 56 MB
- Stars: 229
- Watchers: 12
- Forks: 47
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/Gurobi/gurobi-machinelearning/actions/workflows/push.yml?query=branch%3Amain++)
[](https://github.com/Gurobi/gurobi-machinelearning/actions/workflows/build_wheel.yml?query=branch%3Amain++)

[](https://github.com/psf/black)
[](https://pypi.org/project/gurobi-machinelearning)
[](https://gurobi-machinelearning.readthedocs.io/en/stable/?badge=stable)
[](https://support.gurobi.com/hc/en-us/community/topics/10373864542609-GitHub-Projects)
[](https://www.gurobi.com)
# Gurobi Machine Learning
Gurobi Machine Learning is an [open-source](https://gurobi-machinelearning.readthedocs.io/en/latest/meta/license.html) python package to formulate trained regression models in a [`gurobipy`](https://pypi.org/project/gurobipy/) model to be solved with the Gurobi solver.
The package currently supports various [scikit-learn](https://scikit-learn.org/stable/) objects. It has limited support for [Keras](https://keras.io/), [PyTorch](https://pytorch.org/) and [XGBoost](https://www.xgboost.ai). Only neural networks with ReLU activation can be used with Keras and PyTorch.
# Documentation
The latest user manual is available on [readthedocs](https://gurobi-machinelearning.readthedocs.io/).
# Contact us
For questions related to using Gurobi Machine Learning please use [Gurobi's Forum](https://support.gurobi.com/hc/en-us/community/topics/10373864542609-GitHub-Projects).
For reporting bugs, issues and feature requests please
[open an issue](https://github.com/Gurobi/gurobi-machinelearning/issues).
If you encounter issues with Gurobi or ``gurobipy`` please contact
[Gurobi Support](https://support.gurobi.com/hc/en-us).
# Installation
## Dependencies
`gurobi-machinelearning` requires the following:
- Python >= 3.9
- [`numpy`](https://pypi.org/project/numpy/) >= 1.23.0
- [`gurobipy`](https://pypi.org/project/gurobipy/) >= 10.0
- [`scipy`](https://pypi.org/project/scipy/) >= 1.9.3
The current version supports the following ML packages:
- [`torch`](https://pypi.org/project/torch/)
- [`scikit-learn`](https://pypi.org/project/scikit-learn)
- [`tensorflow`](https://pypi.org/project/tensorflow)
- [`XGBoost`](https://pypi.org/project/xgboost/)
Installing these packages is only required if the predictor you want to insert uses them
(i.e. to insert a Keras based predictor you need to have `tensorflow` installed).
The up to date supported and tested versions of each package for the last release can be
[found in the documentation](https://gurobi-machinelearning.readthedocs.io/en/stable/user/start.html#id7).
## Pip installation
The easiest way to install `gurobi-machinelearning` is using `pip` in a virtual environment:
```shell
(.venv) pip install gurobi-machinelearning
```
This will also install the `numpy`, `scipy` and `gurobipy` dependencies.
Please note that `gurobipy` is commercial software and requires a license. When installed via pip or conda,
`gurobipy` ships with a free license which is only for testing and can only solve models of limited size.
# Getting a Gurobi License
Alternatively to the bundled limited license, there are licenses that can handle models of all sizes.
As a student or staff member of an academic institution you qualify for a free, full product license.
For more information, see:
* https://www.gurobi.com/academia/academic-program-and-licenses/
For a commercial evaluation, you can
[request an evaluation license](https://www.gurobi.com/free-trial/?utm_source=internal&utm_medium=documentation&utm_campaign=fy21_pipinstall_eval_pypipointer&utm_content=c_na&utm_term=pypi).
Other useful resources to get started:
* https://www.gurobi.com/documentation/
* https://support.gurobi.com/hc/en-us/community/topics/
# Development
We value any level of experience in using Gurobi Machine Learning and would like to encourage you to
contribute directly to this project. Please see the [Contributing Guide](CONTRIBUTING.md) for more information.
## Source code
You can clone the latest sources with the command:
```shell
git clone git@github.com:Gurobi/gurobi-machinelearning.git
```
## Testing
After cloning the project, you can run the tests by invoking `tox`. For this, you will need to create a virtual
environment and activate it:
```shell
python3.10 -m venv .venv
. .venv/bin/activate
```
Then, you can install `tox` (>= 3.26.0) and run a few basic tests:
```shell
(.venv) pip install tox
(.venv) tox -e py310,pre-commit,docs
```
`tox` will install, among others, the aforementioned ML packages into a separate `venv`. These packages can be quite
large, so this might take a while.
### Running the full test set
In the above command, we only ran a subset of tests. Running the full set of tests requires having a Gurobi license
installed, and is done by running just the `tox` command without the `-e` parameter:
```shell
(.venv) pip install tox
(.venv) tox
```
If you don't have a Gurobi license, you can still run the subset of tests, open a PR, and Github Actions will run the
tests with a full Gurobi license.
## Submitting a Pull Request
Before opening a Pull Request, have a look at the full [Contributing page](CONTRIBUTING.md) to make sure your code
complies with our guidelines.