Search code examples
pythonjupyter-notebookpicklestatsmodels

How to interact with ML model saved using python pickle module?


I saved a ML model, written using pandas, numpy and statsmodels library, using pickle module.

I then tested loading it into a new jupyter notebook and while it seems to load successfully, I'm not sure how to interact with it from the notebook. This is my first time to attempt such a thing so I'm lost as to how to begin.

This is the code for loading the model. 'Loaded' is printed in the output - no other errors are coming back.

# load your model
import pickle                         
with open('./model.pkl', 'rb') as f:
    model = pickle.load(f)
    print('Loaded')

Solution

  • This is a normal model, treat is as if you never pickled it in the first place. The magic of pickle is that you can save (almost) any object, load it later and use it without any problem.