Predict behavior to retain customers
Data from https://www.kaggle.com/blastchar/telco-customer-churn
Suppose we have a service for running marketing campaigns. For each customer, it needs to determine the probability of churn, and if it’s high enough, it will send a promotional email with discounts. Of course, this service needs to use our model to decide whether it should send an email.
✅ Flask web service
✅ Docker
✅ AWS EC2 & Elastic Beanstalk
![aws-jupyter-notebook](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/aws-jupyter-notebook.png)
we need to create a churn service — a service in Python that will serve the
churn model. Given the features of a customer, it will respond with the probability of
churn for this customer. For each customer, the campaign service will ask the churn
service for the probability of churn, and if it’s high enough, then we send a promotional email
✅ Gets the customer data in a request
✅ Invokes predict_simple to score the customer
✅ Responds with the probability of churn in JSON
✅ Packaged the app with Docker and deployed using AWS Elastic Beanstalk
• Assigns the /predict route to the predict function
• Gets the content of the request in JSON
• Scores the customer
• Prepares the response
• Converts the response to JSON
![Serving-Flask](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/Serving-Flask.png)
![Serving-Docker](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/serving-docker.png)
![Serving-EB](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/serving-eb-local.png)
![Serving-EB](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/serving-eb-ec2-aws.png)
![Streamlit-batch-data-upload](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/app-batch-data-upload-txt-dict.png)
![Streamlit-1](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/streamlit-1.png)
![Streamlit-2](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/streamlit-2.png)
![churn](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/prediction-churn.png)
![no-churn](https://raw.githubusercontent.com/Tauhait/telco-customer-churn/main/imgs/prediction-no-churn.png)
pipenv install
To connect to AWS EC2 instance:
ssh -i "bookcamp.cer" ubuntu@ec2-43-204-32-195.ap-south-1.compute.amazonaws.com
Docker command to run container:
docker run -it -p 9696:9696 churn-prediction:latest
Command to run Gunicorn: (Gunicorn "Green Unicorn" is a Python Web Server Gateway Interface HTTP server)
pipenv run gunicorn --bind 0.0.0.0:9696 churn_serving:app
AWS Elastic Beanstalk create env, run locally and remote:
eb init -p docker churn-serving eb local run --port 9696 eb create churn-serving-env
Streamlit run
pipenv run streamlit run app.py