M_Sabatino
M_Sabatino

Reputation: 1

FileNotFoundError when I pickle my ML model and comment it out

I am receiving an error message while trying to load a pickled ML model for a data project. How to resolve it?

I have the correct file path and already confirmed the path "/home/jovyan/work", and loaded the pickle before.

I don't know if it is a cloud issue, but when I comment out the writing of the pickle alone, or if I comment out the writing of the pickle and the fitting of the model also... I cannot simply load the pickle for some reason. Which is the whole reason I am pickling the model to not have to fit the model every time.

These are the functions i am using:

def write_pickle(path, model_object, save_as:str): 

  with open(path + save_as + ".pickle", "wb") as to_write: 
    
    pickle.dump(model_object, to_write)

def read_pickle(path, saved_model_name:str):
  
    with open(path + saved_model_name + '.pickle', 'rb') as to_read:
        
      model = pickle.load(to_read)
    
    return model

These functions have worked with the file path and everything, but when i comment out the writing of the pickle or comment out the fitting of the ML model.... I am getting a FileNotFoundError. I don't know what the problem could be. Without me being able to figure this out, it seems that it is useless for me to even be pickling the model.

Upvotes: -1

Views: 72

Answers (1)

Jaiv Burman
Jaiv Burman

Reputation: 13

If you comment out your writing then ensure that the model has been already pickled and present in the specified directory which you can check by:

import os
print(os.listdir("home/jovyan/work"))

Also, since its a "FileNotFoundError" and if you're running this in different environment while you mentioned before that it can be a cloud issue....it can be because you might be using the relative path rather than absolute path.

Upvotes: 0

Related Questions