Saving trained model

In most cases, for training the model with the dataset we have is very time consuming and also processing hungry job which is costly task. To test in our development environment we have to do is test the trained model or use the trained model for in production without going for multiple training.

If you have done some ML project you would have understood, how time and processor consuming task it is even when done in GPUs. For a application to use the model and train each time the application runs is unacceptable, so we can save the current trained state of the model for later use without of retraining the model on the same dataset again and again.

We can accomplish this in python using some packages like

  • Pickle (Python Object Serialization Library)
  • Joblib (One of the Scikit-learn Method)


You might have heard this term somewhere when you go though ML articles or doing projects. This library is popular for Serialization(Pickling) and Marshalling (Unpickling). Pickling is the process of converting any Python object into a stream of bytes in hierarchy.Unpickling is process of converting the pickled stream of bytes to original python object following the object hierarchy.


Serialization (Pickling)
import pickle

pickle_file = 'string_list_pickle.pkl'
names = ['apple', 'ball', 'cat']

store_pickle = open(pickle_file, 'wb')
pickle.dump(names, store_pickle)

Read moreSaving trained model