# Module `miplearn.classifiers`

Expand source code

    #  MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
    #  Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
    #  Released under the modified BSD license. See COPYING.md for more details.

    from abc import ABC, abstractmethod

    import numpy as np

    class Classifier(ABC):
        @abstractmethod
        def fit(self, x_train, y_train):
            pass

        @abstractmethod
        def predict_proba(self, x_test):
            pass

        def predict(self, x_test):
            proba = self.predict_proba(x_test)
            assert isinstance(proba, np.ndarray)
            assert proba.shape == (x_test.shape[0], 2)
            return (proba[:, 1] > 0.5).astype(float)

    class Regressor(ABC):
        @abstractmethod
        def fit(self, x_train, y_train):
            pass

        @abstractmethod
        def predict(self):
            pass

## Sub-modules

`miplearn.classifiers.adaptive`
`miplearn.classifiers.counting`
`miplearn.classifiers.cv`
`miplearn.classifiers.evaluator`
`miplearn.classifiers.tests`
`miplearn.classifiers.threshold`

## Classes

`class Classifier`

  Helper class that provides a standard way to create an ABC using inheritance.

  Expand source code

      class Classifier(ABC):
          @abstractmethod
          def fit(self, x_train, y_train):
              pass

          @abstractmethod
          def predict_proba(self, x_test):
              pass

          def predict(self, x_test):
              proba = self.predict_proba(x_test)
              assert isinstance(proba, np.ndarray)
              assert proba.shape == (x_test.shape[0], 2)
              return (proba[:, 1] > 0.5).astype(float)

  ### Ancestors

  - abc.ABC

  ### Subclasses

  - AdaptiveClassifier
  - CountingClassifier
  - CrossValidatedClassifier

  ### Methods

  `def fit(self, x_train, y_train)`
    Expand source code

        @abstractmethod
        def fit(self, x_train, y_train):
            pass

  `def predict(self, x_test)`
    Expand source code

        def predict(self, x_test):
            proba = self.predict_proba(x_test)
            assert isinstance(proba, np.ndarray)
            assert proba.shape == (x_test.shape[0], 2)
            return (proba[:, 1] > 0.5).astype(float)

  `def predict_proba(self, x_test)`
    Expand source code

        @abstractmethod
        def predict_proba(self, x_test):
            pass

`class Regressor`

  Helper class that provides a standard way to create an ABC using inheritance.

  Expand source code

      class Regressor(ABC):
          @abstractmethod
          def fit(self, x_train, y_train):
              pass

          @abstractmethod
          def predict(self):
              pass

  ### Ancestors

  - abc.ABC

  ### Methods

  `def fit(self, x_train, y_train)`
    Expand source code

        @abstractmethod
        def fit(self, x_train, y_train):
            pass

  `def predict(self)`
    Expand source code

        @abstractmethod
        def predict(self):
            pass