-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from samirmartins/master
Adding save_model and load_model as a new util
- Loading branch information
Showing
2 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|