11. Collectors & Extractors

11.1. miplearn.classifiers.minprob

class miplearn.classifiers.minprob.MinProbabilityClassifier(base_clf: Any, thresholds: List[float], clone_fn: Callable[[Any], Any] = <function clone>)

Bases: sklearn.base.BaseEstimator

Meta-classifier that returns NaN for predictions made by a base classifier that have probability below a given threshold. More specifically, this meta-classifier calls base_clf.predict_proba and compares the result against the provided thresholds. If the probability for one of the classes is above its threshold, the meta-classifier returns that prediction. Otherwise, it returns NaN.

fit(x: numpy.ndarray, y: numpy.ndarray)None
predict(x: numpy.ndarray)numpy.ndarray
set_fit_request(*, x: Union[bool, None, str] = '$UNCHANGED$')miplearn.classifiers.minprob.MinProbabilityClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in fit.

Returns

self – The updated object.

Return type

object

set_predict_request(*, x: Union[bool, None, str] = '$UNCHANGED$')miplearn.classifiers.minprob.MinProbabilityClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in predict.

Returns

self – The updated object.

Return type

object

11.2. miplearn.classifiers.singleclass

class miplearn.classifiers.singleclass.SingleClassFix(base_clf: sklearn.base.BaseEstimator, clone_fn: Callable = <function clone>)

Bases: sklearn.base.BaseEstimator

Some sklearn classifiers, such as logistic regression, have issues with datasets that contain a single class. This meta-classifier fixes the issue. If the training data contains a single class, this meta-classifier always returns that class as a prediction. Otherwise, it fits the provided base classifier, and returns its predictions instead.

fit(x: numpy.ndarray, y: numpy.ndarray)None
predict(x: numpy.ndarray)numpy.ndarray
set_fit_request(*, x: Union[bool, None, str] = '$UNCHANGED$')miplearn.classifiers.singleclass.SingleClassFix

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in fit.

Returns

self – The updated object.

Return type

object

set_predict_request(*, x: Union[bool, None, str] = '$UNCHANGED$')miplearn.classifiers.singleclass.SingleClassFix

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters

x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for x parameter in predict.

Returns

self – The updated object.

Return type

object

11.3. miplearn.collectors.basic

class miplearn.collectors.basic.BasicCollector(skip_lp: bool = False, write_mps: bool = True)

Bases: object

collect(filenames: List[str], build_model: Callable, n_jobs: int = 1, progress: bool = False, verbose: bool = False)None

11.4. miplearn.extractors.fields

class miplearn.extractors.fields.H5FieldsExtractor(instance_fields: Optional[List[str]] = None, var_fields: Optional[List[str]] = None, constr_fields: Optional[List[str]] = None)

Bases: miplearn.extractors.abstract.FeaturesExtractor

get_constr_features(h5: miplearn.h5.H5File)numpy.ndarray
get_instance_features(h5: miplearn.h5.H5File)numpy.ndarray
get_var_features(h5: miplearn.h5.H5File)numpy.ndarray

11.5. miplearn.extractors.AlvLouWeh2017

class miplearn.extractors.AlvLouWeh2017.AlvLouWeh2017Extractor(with_m1: bool = True, with_m2: bool = True, with_m3: bool = True)

Bases: miplearn.extractors.abstract.FeaturesExtractor

get_constr_features(h5: miplearn.h5.H5File)numpy.ndarray
get_instance_features(h5: miplearn.h5.H5File)numpy.ndarray
get_var_features(h5: miplearn.h5.H5File)numpy.ndarray
Computes static variable features described in:

Alvarez, A. M., Louveaux, Q., & Wehenkel, L. (2017). A machine learning-based approximation of strong branching. INFORMS Journal on Computing, 29(1), 185-195.