mlrl.testbed.output_writer module

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

Provides utilities for writing output data to sinks like the console or output files.

class mlrl.testbed.output_writer.Formattable

Bases: ABC

An abstract base class for all classes from which a textual representation can be created.

abstract format(options: Options, **kwargs) str

Creates and returns a textual representation of the object.

Parameters:

options – Options to be taken into account

Returns:

The textual representation that has been created

class mlrl.testbed.output_writer.OutputWriter(sinks: List[Sink])

Bases: ABC

An abstract base class for all classes that allow to write output data to one or several sinks, e.g., the console or output files.

class CsvSink(output_dir: str, file_name: str, options: ~mlrl.common.options.Options = <mlrl.common.options.Options object>)

Bases: Sink

Allows to write output data to a CSV file.

write_output(meta_data: MetaData, data_split: DataSplit, data_type: DataType | None, prediction_scope: PredictionScope | None, output_data, **kwargs)

Must be implemented by subclasses in order to write output data to the sink.

Parameters:
  • meta_data – The meta data of the data set

  • data_split – Information about the split of the available data, the output data corresponds to

  • data_type – Specifies whether the predictions and ground truth labels correspond to the training or test data or None, if no predictions have been obtained

  • prediction_scope – Specifies whether the predictions have been obtained from a global model or incrementally or None, if no predictions have been obtained

  • output_data – The output data that should be written to the sink

KWARG_DATA_SPLIT = 'data_split'
class LogSink(title: str, options: ~mlrl.common.options.Options = <mlrl.common.options.Options object>)

Bases: Sink

Allows to write output data to the console.

write_output(meta_data: MetaData, data_split: DataSplit, data_type: DataType | None, prediction_scope: PredictionScope | None, output_data, **kwargs)

Must be implemented by subclasses in order to write output data to the sink.

Parameters:
  • meta_data – The meta data of the data set

  • data_split – Information about the split of the available data, the output data corresponds to

  • data_type – Specifies whether the predictions and ground truth labels correspond to the training or test data or None, if no predictions have been obtained

  • prediction_scope – Specifies whether the predictions have been obtained from a global model or incrementally or None, if no predictions have been obtained

  • output_data – The output data that should be written to the sink

class Sink(options: ~mlrl.common.options.Options = <mlrl.common.options.Options object>)

Bases: ABC

An abstract base class for all sinks, output data may be written to.

abstract write_output(meta_data: MetaData, data_split: DataSplit, data_type: DataType | None, prediction_scope: PredictionScope | None, output_data, **kwargs)

Must be implemented by subclasses in order to write output data to the sink.

Parameters:
  • meta_data – The meta data of the data set

  • data_split – Information about the split of the available data, the output data corresponds to

  • data_type – Specifies whether the predictions and ground truth labels correspond to the training or test data or None, if no predictions have been obtained

  • prediction_scope – Specifies whether the predictions have been obtained from a global model or incrementally or None, if no predictions have been obtained

  • output_data – The output data that should be written to the sink

class TxtSink(output_dir: str, file_name: str, options: ~mlrl.common.options.Options = <mlrl.common.options.Options object>)

Bases: Sink

Allows to write output data to a text file.

write_output(meta_data: MetaData, data_split: DataSplit, data_type: DataType | None, prediction_scope: PredictionScope | None, output_data, **kwargs)

Must be implemented by subclasses in order to write output data to the sink.

Parameters:
  • meta_data – The meta data of the data set

  • data_split – Information about the split of the available data, the output data corresponds to

  • data_type – Specifies whether the predictions and ground truth labels correspond to the training or test data or None, if no predictions have been obtained

  • prediction_scope – Specifies whether the predictions have been obtained from a global model or incrementally or None, if no predictions have been obtained

  • output_data – The output data that should be written to the sink

write_output(meta_data: MetaData, x, y, data_split: DataSplit, learner, data_type: DataType | None = None, prediction_type: PredictionType | None = None, prediction_scope: PredictionScope | None = None, predictions: Any | None = None, train_time: float = 0, predict_time: float = 0)

Generates the output data and writes it to all available sinks.

Parameters:
  • meta_data – The meta-data of the data set

  • x – A numpy.ndarray or scipy.sparse matrix, shape (num_examples, num_features), that stores the feature values

  • y – A numpy.ndarray or scipy.sparse matrix, shape (num_examples, num_labels), that stores the ground truth labels

  • data_split – Information about the split of the available data, the output data corresponds to

  • learner – The learner that has been trained

  • data_type – Specifies whether the predictions and ground truth labels correspond to the training or test data or None, if no predictions have been obtained

  • prediction_type – The type of the predictions or None, if no predictions have been obtained

  • prediction_scope – Specifies whether the predictions have been obtained from a global model or incrementally or None, if no predictions have been obtained

  • predictions – A numpy.ndarray or scipy.sparse matrix, shape (num_examples, num_labels), that stores the predictions for the query examples or None, if no predictions have been obtained

  • train_time – The time needed for training or 0, if no model has been trained

  • predict_time – The time needed for prediction or 0, if no predictions have been obtained

class mlrl.testbed.output_writer.Tabularizable

Bases: ABC

An abstract base class for all classes from which a tabular representation can be created.

abstract tabularize(options: Options, **kwargs) List[Dict[str, str]] | None

Creates and returns a tabular representation of the object.

Parameters:

options – Options to be taken into account

Returns:

The tabular representation that has been created