Skip to content

Commit

Permalink
Merge pull request #74 from samirmartins/master
Browse files Browse the repository at this point in the history
Adding save_model and load_model as a new util
  • Loading branch information
wilsonrljr authored Mar 4, 2022
2 parents 3d241ff + 533fd9c commit 0ec9efe
Show file tree
Hide file tree
Showing 2 changed files with 253 additions and 0 deletions.
179 changes: 179 additions & 0 deletions examples/save_and_load_models.ipynb

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions sysidentpy/utils/save_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Author:
# Samir Angelo Milani Martins https://github.com/samirmartins
# License: BSD 3 clause

import pickle as pk
import os

def save_model(
model,
file_name,
path = None,
):
""" This method saves the model "model" in folder "folder" using an extension .syspy
Parameters
----------
model: the model variable to be saved
file_name: file name, along with .syspy extension
path: location where the model will be saved (optional)
Returns
----------
file file_name.syspy located at "path", containing the estimated model.
"""

# Checking if path is provided
if path is not None:

# Composing file_name with path
file_name = os.path.join(path,file_name)

# Saving model
with open(file_name, "wb") as fp:
pk.dump(model, fp)


def load_model(
file_name,
path = None,
):

""" This method loads the model from file "file_name.syspy" located at path "path"
Parameters
----------
file_name: file name (str), along with .syspy extension of the file containing model to be loaded
path: location where "file_name.syspy" is (optional).
Returns
----------
model_loaded: model loaded, as a variable, containing model and its atributes
"""
# Checking if path is provided
if path is not None:

# Composing file_name with path
file_name = os.path.join(path,file_name)


# Loading the model
with open(file_name, 'rb') as fp:
model_loaded = pk.load(fp)


return model_loaded


0 comments on commit 0ec9efe

Please sign in to comment.