@@ -265,6 +266,27 @@ Mean absolute error 65.843924 R2 0.517612 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.

+
from miplearn import PrimalSolutionComponent
+from sklearn.neighbors import KNeighborsClassifier
+
+comp = PrimalSolutionComponent(classifier=KNeighborsClassifier(n_neighbors=5))
+comp.fit(train_instances)