Supported ML Models
###########################
The package currently supports various `Scikit-Learn
`_ objects. It can also embed
gradient boosting regression models from `XGBoost `_, and
`LightGBM `_. Finally, it supports Sequential Neural Networks from
`PyTorch `_ and `Keras `_.
In :doc:`Mixed Integer Formulations <./formulations>`, we briefly outline the
MIP formulations used for the various ML models.
Scikit-learn
------------
The following table lists the name of the models supported, the name of the
corresponding object in the Python framework, and the function that can be used
to insert it in a SCIP model.
.. list-table:: Supported ML models of :external+sklearn:std:doc:`scikit-learn `
:widths: 25 25 50
:header-rows: 1
* - Machine Learning Model
- Scikit-learn object
- Functions to insert
* - Ordinary Least Square
- :external:py:class:`LinearRegression
`
:external:py:class:`Ridge
`
:external:py:class:`ElasticNet
`
:external:py:class:`Lasso
`
- :py:mod:`add_linear_regression_constr
`
* - Partial Least Square
- :external:py:class:`PLSRegression
`
:external:py:class:`PLSRegression
`
- :py:mod:`add_pls_regression_constr
`
* - Logistic Regression
- :external:py:class:`LogisticRegression
`
- :py:mod:`add_logistic_regression_constr
`
* - Neural-network
- :external:py:class:`MLPRegressor
`
:external:py:class:`MLPClassifier
`
- :py:mod:`add_mlp_regressor_constr
`
:py:mod:`add_mlp_classifier_constr
`
* - Decision tree
- :external:py:class:`DecisionTreeRegressor
`
:external:py:class:`DecisionTreeClassifier
`
- :py:mod:`add_decision_tree_regressor_constr
`
:py:mod:`add_decision_tree_classifier_constr
`
* - Gradient boosting
- :external:py:class:`GradientBoostingRegressor
`
:external:py:class:`GradientBoostingClassifier
`
- :py:mod:`add_gradient_boosting_regressor_constr
`
:py:mod:`add_gradient_boosting_classifier_constr
`
* - Random Forest
- :external:py:class:`RandomForestRegressor
`
:external:py:class:`RandomForestClassifier
`
- :py:mod:`add_random_forest_regressor_constr
`
:py:mod:`add_random_forest_classifier_constr
`
* - Support Vector Machines
- :external:py:class:`SVR
`
:external:py:class:`SVC
`
:external:py:class:`LinearSVR
`
:external:py:class:`LinearSVC
`
- :py:mod:`add_support_vector_regressor_constr
`
:py:mod:`add_support_vector_classifier_constr
`
* - Centroid Clustering
- :external:py:class:`KMeans
`
:external:py:class:`MiniBatchKMeans
`
- :py:mod:`add_centroid_cluster_constr
`
* - Pipeline
- :external:py:class:`Pipeline
`
- :py:mod:`add_pipeline_constr
`
* - MultiOutput
- :external:py:class:`MultiOutputClassifier
`
:external:py:class:`MultiOutputRegressor
`
- :py:mod:`add_multi_output_classifier_constr
`
:py:mod:`add_multi_output_regressor_constr
`
PyTorch
-------
In PyTorch, only :external+torch:py:class:`torch.nn.Sequential` objects are
supported.
They can be embedded in a SCIP model with the function
:py:func:`pyscipopt_ml.torch.add_sequential_constr`.
Currently, only five types of layers are supported:
* :external+torch:py:class:`Linear layers `,
* :external+torch:py:class:`ReLU layers `,
* :external+torch:py:class:`Sigmoid layers `,
* :external+torch:py:class:`Tanh layers `
* :external+torch:py:class:`Softmax layers `
* :external+torch:py:class:`Softplus layers `
In the case of the final layer being an activation function used for classification, e.g.
:external+torch:py:class:`Softmax `, simply set
`output_type=="classification"` when inserting the predictor constraint.
The result is that the class with highest value
is assigned value 1 and all other classes are assigned value 0. Essentially, explicitly modelling
the final activation function for classification purposes is unnecessary from a MIP perspective as
the maximum value is preserved after the function is applied.
Keras
------
For Keras, only `keras.Model `_ and
`keras.Sequential `_ are supported.
They can be embedded in a SCIP model with the function
:py:func:`pyscipopt_ml.keras.add_keras_constr`.
The supported layer types and activation functions are the same as in torch (see above).
This support holds for the classification case when the final layer is an unsupported activation function,
e.g. softmax. Please read the above explanation in the PyTorch section, and in such use cases set
`output_type="classification"` when inserting the predictor constraint.
ONNX
----
For ONNX we also support standard feed forward neural networks. These must be
provided in the `ModelProto `_ format.
They can be embedded in a SCIP model with the function
:py:func:`pyscipopt_ml.onnx.add_onnx_constr`.
The supported layer types and activation functions are the same as in torch and keras (see above).
The classification trick for the final layer is not done for ONNX models, so be warned that there will
be a performance difference for imported classification models.
XGBoost
-------
Models for XGBoost's Scikit-Learn interface can be embedded in a SCIP model.
The following table lists the name of the models supported, the name of the
corresponding object in the Python framework, and the function that can be used
to insert it in a SCIP model.
.. list-table:: Supported ML models of :external+xgb:std:doc:`xgboost `
:widths: 25 50
:header-rows: 1
* - XGBoost object
- Function to insert
* - :external+xgb:py:class:`xgboost.XGBRegressor `
- :py:mod:`add_xgbregressor_constr
`
* - :external+xgb:py:class:`xgboost.XGBClassifier `
- :py:mod:`add_xgbclassifier_constr
`
* - :external+xgb:py:class:`xgboost.XGBRFRegressor `
- :py:mod:`add_xgbregressor_rf_constr
`
* - :external+xgb:py:class:`xgboost.XGBRFClassifier `
- :py:mod:`add_xgbclassifier_rf_constr
`
Currently only "gbtree" boosters are supported.
LightGBM
--------
Models for LightGBM's Scikit-Learn interface can be embedded in a SCIP model.
The following table lists the name of the models supported, the name of the
corresponding object in the Python framework, and the function that can be used
to insert it in a SCIP model.
.. list-table:: Supported ML models of :external+lgb:std:doc:`lightgbm `
:widths: 25 50
:header-rows: 1
* - LightGBM object
- Function to insert
* - :external+lgb:py:class:`lightgbm.LGBMRegressor `
- :py:mod:`add_lgbregressor_constr
`
* - :external+lgb:py:class:`lightgbm.LGBMClassifier `
- :py:mod:`add_lgbclassifier_constr
`
Currently "gbdt" and "rf" boosters are supported.