0

I created grid_search.pkl file for model persitence after fitting it in Jupyter Notebook like this:

joblib.dump(grid_search, 'grid_search_rf.pkl', compress=3)

after a while, I have moved my .ipynb file to subdirectory called notebooks and also I did some refactoring to my modules in parent directory of notebooks

now when trying to load this grid_search.pkl file into my notebook which is in subdirectory (of parent directory with contain my modules) like this:

grid_search = joblib.load('../grid_search_rf.pkl')

I get this weird error about one of my modules which doesn't seems to be related.

However when jupyter notebook is directly in my parent dir with all .py modules and .pkl files, grid_search.pkl file is loaded correctly.

Why? How can I load this .pkl file while having .ipynb file in subdirectory of that parent dir?

EDIT: I have added class TextParser (based on weird error) which I have removed during refactoring in one of my module and now everything works fine and I can load grid_search.pkl from parent directory into jupyter notebooks as they are in subdirectory notebooks, can someone please explain this behaviour of pickling?

PeterB
  • 2,234
  • 6
  • 24
  • 43

1 Answers1

0

I suspect that the Pickle file references some module that is not on your PYTHONPATH. Try inserting the following code before loading the Pickle:

import sys
sys.path.append("..")
mvoelske
  • 347
  • 2
  • 7