mlrl.testbed_sklearn.experiments.prediction.predictor module

Author: Michael Rapp (michael.rapp.ml@gmail.com)

Provides classes for obtaining predictions from machine learning models.

class mlrl.testbed_sklearn.experiments.prediction.predictor.PredictionFunction(learner: Any, predict_function: Callable[[...], Any] | None, decision_function: Callable[[...], Any] | None, predict_proba_function: Callable[[...], Any] | None)

Bases: object

A function that obtains and returns predictions from a learner.

invoke(dataset: Any, prediction_type: PredictionType, **kwargs) Any

Invokes the correct prediction function, depending on the type of the predictions that should be obtained.

Parameters:
  • dataset – The dataset that stores the query examples

  • prediction_type – The type of the predictions that should be obtained

  • kwargs – Optional keyword arguments to be passed to the prediction function

Returns:

The predictions that have been obtained

class mlrl.testbed_sklearn.experiments.prediction.predictor.Predictor(prediction_type: PredictionType)

Bases: ABC

An abstract base class for all classes that allow to obtain predictions from a previously trained model.

abstractmethod obtain_predictions(learner: Any, dataset: Any, dataset_type: DatasetType, **kwargs) Generator[PredictionState, None, None]

Obtains predictions from a previously trained learner once or several times.

Parameters:
  • learner – The learner

  • dataset – The dataset that contains the query examples

  • dataset_type – The type of the dataset

  • kwargs – Optional keyword arguments to be passed to the learner when obtaining predictions

Returns:

A generator that provides access to the results of the individual prediction processes