5 Deploying machine learning models

 

This chapter covers

  • Saving models with Pickle
  • Serving models with Flask
  • Managing dependencies with Pipenv
  • Making the service self-contained with Docker
  • Deploying it to the cloud using AWS Elastic Beanstalk

As we continue to work with machine learning techniques, we’ll keep using the project we already started: churn prediction. In chapter 3, we used Scikit-learn to build a model for identifying churning customers. After that, in chapter 4, we evaluated the quality of this model and selected the best parameter C using cross-validation.

We already have a model that lives in our Jupyter Notebook. Now we need to put this model into production, so other services can use the model to make decisions based on the output of our model.

In this chapter, we cover model deployment : the process of putting models to use. In particular, we see how to package a model inside a web service, so other services can use it. We also see how to deploy the web service to a production-ready environment.

5.1 Churn-prediction model

To get started with deployment we use the model we trained previously. First, in this section, we review how we can use the model for making predictions, and then we see how to save it with Pickle.

5.1.1 Using the model

To make it easier, we can continue the same Jupyter Notebook we used for chapters 3 and 4.

Let’s use this model to calculate the probability of churning for the following customer:

5.1.2 Using Pickle to save and load the model

5.2 Model serving

5.2.1 Web services

5.2.2 Flask

5.2.3 Serving churn model with Flask

5.3 Managing dependencies

5.3.1 Pipenv

5.3.2 Docker

5.4 Deployment

5.4.1 AWS Elastic Beanstalk

5.5 Next steps

5.5.1 Exercises

Summary