Skip to content

src.model.io

save_model(model, model_name)

Saves a model artefact to the file system..

Parameters:

Name Type Description Default
model object

Model to be saved

required
model_name str

Name under which the model should be saved.

required
Source code in reproML/src/model/io.py
 7
 8
 9
10
11
12
13
14
15
16
17
@log
def save_model(model: object, model_name: str) -> None:
    """Saves a model artefact to the file system..

    Args:
        model (object): Model to be saved
        model_name (str): Name under which the model should be saved.
    """
    outfile_path = get_path(model_name=model_name)
    with open(outfile_path, "wb") as outfile:
        dump(model, outfile)

load_model(model_name)

Loads a model from the file system.

Parameters:

Name Type Description Default
model_name str

Name given to the model when saved.

required

Returns:

Name Type Description
object object

Model

Source code in reproML/src/model/io.py
20
21
22
23
24
25
26
27
28
29
30
31
32
@log
def load_model(model_name: str) -> object:
    """Loads a model from the file system.

    Args:
        model_name (str): Name given to the model when saved.

    Returns:
        object: Model
    """
    infile_path = get_path(model_name=model_name)
    with open(infile_path, "rb") as infile:
        return load(infile)

get_path(model_name)

Constructs path for a model artefact.

Parameters:

Name Type Description Default
model_name str

Name given to the model

required

Returns:

Name Type Description
str str

Model artefact path

Source code in reproML/src/model/io.py
35
36
37
38
39
40
41
42
43
44
45
@log
def get_path(model_name: str) -> str:
    """Constructs path for a model artefact.

    Args:
        model_name (str): Name given to the model

    Returns:
        str: Model artefact path
    """
    return path.join("models", f"{model_name}.cldpkl")