Wrappers

BaseWrapper

class a2pm.wrappers.BaseWrapper(**params)

Bases: object

Base Classifier Wrapper.

A wrapper encapsulates a classifier that is ready to provide class predictions (is already fitted) for the generate method. This base class cannot be directly utilized.

Additionally, a wrapped classifier can also be used as a class_discriminator function, to be called to identify the Class ID of each sample.

It must be a class implementing the predict method, according to the following signature:

predict(self, X) -> y

Parameters

**params (dict of ‘parameter name - value’ pairs) – Optional parameters to provide to the classifier during the class prediction process.

KerasWrapper

class a2pm.wrappers.KerasWrapper(classifier, classes=None, **params)

Bases: a2pm.wrappers.base_wrapper.BaseWrapper

Keras Classifier Wrapper.

Encapsulates a Tensorflow/Keras classification model.

Parameters
  • classifier (object with a predict method) – Fitted classifier to be wrapped.

  • classes (list of Class IDs or None (default None)) – Classes to convert predictions to, using the indices provided by the prediction process.

    Set to None to use the default class indices.

  • **params (dict of ‘parameter name - value’ pairs) – Optional parameters to provide to the classifier during the prediction process.

predict(X)

Applies the wrapped classifier and converts its class probability predictions.

Parameters

X (array-like in the (n_samples, n_features) shape) – Input data.

Returns

y – The class predictions.

Return type

numpy array of shape (n_samples, )

SklearnWrapper

class a2pm.wrappers.SklearnWrapper(classifier, **params)

Bases: a2pm.wrappers.base_wrapper.BaseWrapper

Sklearn Classifier Wrapper.

Encapsulates a Scikit-Learn classification model.

Parameters
  • classifier (object with a predict method) – Fitted classifier to be wrapped.

  • **params (dict of ‘parameter name - value’ pairs) – Optional parameters to provide to the classifier during the prediction process.

predict(X)

Applies the wrapped classifier directly, without needing to convert its class predictions.

Parameters

X (array-like in the (n_samples, n_features) shape) – Input data.

Returns

y – The class predictions.

Return type

numpy array of shape (n_samples, )

TorchWrapper

class a2pm.wrappers.TorchWrapper(classifier, classes=None, **params)

Bases: a2pm.wrappers.base_wrapper.BaseWrapper

Torch Classifier Wrapper.

Encapsulates a PyTorch classification model.

Parameters
  • classifier (object with a __call__ method) – Fitted classifier to be wrapped.

  • classes (list of Class IDs or None (default None)) – Classes to convert predictions to, using the indices provided by the prediction process.

    Set to None to use the default class indices.

  • **params (dict of ‘parameter name - value’ pairs) – Optional parameters to provide to the classifier during the prediction process.

predict(X)

Applies the wrapped classifier and converts its class probability predictions.

Parameters

X (array-like in the (n_samples, n_features) shape) – Input data.

Returns

y – The class predictions.

Return type

numpy array of shape (n_samples, )