Model Persistence
Learn how to make the Python prediction models persistent.
We'll cover the following
To host a model as a web service, we need to provide a model object for the predict function.
We can train the model within the web service application, or we can use a pre-trained model. Model persistence is a term used for saving and loading models within a predictive model pipeline. It’s more common to train models in a separate workflow than the pipeline used to serve the model, such as a Flask application. In this section, we’ll save and load both scikit-learn and Keras models, with both direct serialization and the MLflow library. The goal of saving and loading these models is to make the logistic regression and deep learning models we built in the Introduction available as web endpoints.
Scikit-Learn
We’ll start with scikit-learn, which we previously used to build a propensity model for identifying which players were most likely to purchase a game.
A simple LogisticRegression
model object can be created using the following script:
Get hands-on with 1400+ tech skills courses.