lir.persistence module

class lir.persistence.SaveModel(output_dir: Path, filename: PathLike | str = 'model.pkl')[source]

Bases: Aggregation

Write the model to a file.

The model is saved as a pickle file, in a file named filename, that is written to a subdirectory of output_dir, that is created for each run.

If filename is an absolute path, or if filename is relative to output_dir, then the model is saved to this file as-is, instead of to a file in a newly created subdirectory.

Once a model is saved, it can be loaded again using the load_model() function.

Parameters:
  • output_dir (Path) – The directory where the model should be written.

  • filename (PathLike | str) – The filename to be created for the model.

report(data: AggregationData) None[source]

Create a directory for the run and write the trained LR system model to file.

Parameters:

data (AggregationData) – The data to be aggregated, containing the trained LR system model and the run name.

lir.persistence.load_model(path: Path) LRSystem[source]

Load previously cached model.

The model is expected to be stored as a pickle file, and is assumed to exclusively contain an LRSystem instance.

Parameters:

path (Path) – The path to the .pkl file containing the model.

Returns:

The loaded model.

Return type:

LRSystem

Examples

from lir.persistence import load_model
from lir import FeatureData

model = load_model(Path('path/to/model.pkl'))
data = FeatureData(...) # some data to apply the model to

model.apply(data)
lir.persistence.save_model(path: Path, model: LRSystem) None[source]

Save a model to disk.

This method is inteded for use with the Python API. For yaml-based configuration of model saving, see the SaveModel aggregation.

Parameters:
  • path (Path) – The path to the .pkl file where the model should be saved.

  • model (LRSystem) – The model to be saved.