Saving a predictive model for production use

Once you create a trained model, you need to save it for production use. Python makes this very easy, you just pickle() it.

Getting Ready

This recipe assumes you've run the previous three recipes, and have three trained models.

How to do it…

  1. First, import the pickle library:
    import pickle
  2. Next, pickle the logistic regression model:
    hearts_classifier_file = "/Users/robertdempsey/Dropbox/private/Python Business Intelligence Cookbook/Models/hearts_lr_classifier_09.27.15.dat"
    pickle.dump(logClassifier, open(hearts_classifier_file, "wb"))
  3. Next, pickle the random forest model:
    hearts_classifier_file = "/Users/robertdempsey/Dropbox/private/Python Business Intelligence Cookbook/Models/hearts_rf_classifier_09.27.15.dat" ...

Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.