Document custom ML models

This commit is contained in:
2020-05-05 13:54:11 -05:00
parent 929ff0d9d8
commit 92cc924fee
5 changed files with 48 additions and 2 deletions

View File

@@ -134,3 +134,27 @@ Median absolute error 65.843924
dtype: float64
```
### Using customized ML classifiers and regressors
By default, given a training set of instantes, MIPLearn trains a fixed set of ML classifiers and regressors, then
selects the best one based on cross-validation performance. Alternatively, the user specify which model a component
should use through the `classifier` or `regressor` contructor parameters. The provided classifiers and regressors must
follow the sklearn API. In particular, classifiers must provide the methods `fit`, `predict_proba` and `predict`,
while regressors must provide the methods `fit` and `predict`
!!! danger
MIPLearn must be able to generate a copy of any custom ML classifiers and regressors through
the standard `copy.deepcopy` method. This currently makes it incompatible with Keras and TensorFlow
predictors. This is a known limitation, which will be addressed in a future version.
The example below shows how to construct a `PrimalSolutionComponent` which internally uses
sklearn's `KNeighborsClassifiers`. Any other sklearn classifier or pipeline can be used.
```python
from miplearn import PrimalSolutionComponent
from sklearn.neighbors import KNeighborsClassifier
comp = PrimalSolutionComponent(classifier=KNeighborsClassifier(n_neighbors=5))
comp.fit(train_instances)
```