0

Below is the code I use for the generator. It is modified from Saving and loading multiple objects in pickle file?. The file was created with joblib.dump, and consists (so far) of a single machine learning model.

import pickle
from sklearn.externals import joblib

filename = 'ML_models.pkl'
def load(filename):
    with open(filename, "rb") as f:
        while True:
            try:
                yield joblib.load(f)
            except EOFError:
                break

Next I test the generator as follows:

models = load(filename)
for model in models:
    print model

Unfortunately, this prints the model repeatedly until I interrupt the kernel. What is the right way to signal EOF?

JGrossman
  • 33
  • 4

1 Answers1

1

According to the documentation, joblib.load returns the full object.

def load(filename):
    with open(filename, "rb") as f:
        return joblib.load(f)
Helio Santos
  • 6,606
  • 3
  • 25
  • 31