Spaces:
Sleeping
Sleeping
File size: 9,286 Bytes
6946341 4eb6f8a 6946341 4eb6f8a 77f3bca 6946341 2953afe 6946341 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
---
title: Customer Churn Prediction App
emoji: π
colorFrom: blue
colorTo: green
sdk: streamlit
app_file: frontend/main.py
pinned: true
sdk_version: 1.40.1
---
# End to End Customer Churn Prediction
## :page_facing_up: Problem Statement
Customer churn is a critical issue for businesses as it directly impacts profitability and growth. This application aims to predict whether a customer will leave a service or product based on historical data and behavioral patterns.
## :dart: Objective
The main objective of this application is to develop a machine learning model that accurately predicts customer churn. By identifying at-risk customers, businesses can take proactive measures to enhance customer retention and improve overall satisfaction.
## π οΈ Technological Stack
- **Python** - The primary programming language used for development.
- **Machine Learning** - Algorithms to analyze customer data and predict churn.
- **MLOps** - Practices for deploying and maintaining machine learning models.
- **ZenML** - A tool to create reproducible ML pipelines.
- **MLflow** - For tracking experiments and managing model lifecycle.
- **Streamlit** - A user-friendly UI framework for creating interactive web applications.
- **FastAPI** - Back-end frameworks to build APIs for model prediction server.
- **Evidently Ai** - A tool for Model Monitering and data drift detection.
## π Overview
This design document outlines the development of a web application for predicting customer churn using a dataset that includes customer Age, Support Calls , Usage Frequency, Last Interaction, Tenure, Contract Length. The application will allow users to input customer data and receive predictions on churn likelihood.
## :snake: Python Requirements
Let's jumpt into python packages you need. you need run below commands in python enivironmemt
```
mkdir customer_churn_prediction
cd customer_churn_prediction
git clone https://github.com/sarathkumar1304/End-to-End-Customer-Churn-Prediction
python3 -m venv venv
```
Activate your virtual environment
```pip install requirements.txt```
Starting with **ZenML** an open source MLOPs Library for machine learning engineer life cycle.ZenML has react base dashboard that allows you to observe your pipeline DAG's, stacks, stack components in dashboard interface.
To access this, you need to launch the ZenML Server and Dashboard locally, we need run run below commands
```
pip install zenml["server"]
zenml up
```
After running this commands we can visualize the dashboard locally in your browser.
Then , you run the pipeline first and then follow the steps.
```
python3 run_pipeline.py
```
run_pipeline.py has all the combined python scripts to run the pipeline at one place.Now we can visualize the pipeline in your web browser.
we can the dashboard like below

Before the deployment we need run some commands, to intergrate with **MLFlow** for Experiment trackering and model registry.
```
zenml integration install mlflow -y
zenml experiment-tracker register mlflow_tracker --flavor=mlflow
zenml model-deployer register mlflow_customer_churn --flavor=mlflow
zenml stack register mlflow_stack_customer_churn -a default -o default -d mlflow -e mlflow_tracker_customer_churn --set
```


After running this command we can track the experiment in mlflow dashboard locally.
```
python3 run_deployment.py
```
After running this command we successfully deploy the model in mlflow server that returns this url for further prediction http://127.0.0.1:8000/invocations for further predicition.
Run the below command to launch the streamlit ui.
```
streamlit run frontend/main.py
```
or we can run whole project using **Docker** by running the below command
```
docker-compose up --build
```
It will run the whole project at once without any error.
## πͺ Motivation
Understanding and addressing customer churn can significantly enhance customer loyalty and reduce marketing costs associated with acquiring new customers. This application provides insights that help businesses to implement effective retention strategies.
## π Success Metrics
The project's success will be measured using the following metrics:
- Precision, Recall, and F1 Score of the churn prediction model.
- Reduction in customer churn rates observed post-implementation.
## π Requirements & Constraints
### Functional Requirements
- Users can input customer data to receive churn predictions.
- Users can view performance metrics of the machine learning models.
- The model should demonstrate high accuracy in predictions.
### π§ Constraints
- The application is built using FastAPI as backend and Streamlit as front end , with deployment on Streamlit cloud and Containerizer using Docker
## βοΈ Methodology
- **Problem Statement**: Develop a model to predict customer churn based on various features.
- **Data**: Utilize a dataset containing customer-related features such as demographics and service usage.
- **Techniques**: Employ data ingestion, data preprocessing, feature engineering, model selection, training, evaluation and model deployment.
- **zenml :** for creating reproducible ML pipeline.
- **MLFlow:** for experiment tracking and model registry.
- **Docker :** for containerization the whole project.
## ποΈ Architecture
The architecture of the web application consists of:
- A **frontend** built using Streamlit for user interaction.
- A **backend** server implemented with FastAPI for handling requests and serving predictions.
- A **machine learning model** for churn prediction.
- Utilization of **Docker** for containerization.
- Hosting on **Streamlit Cloud** with a CI/CD pipeline for automated deployment.
## ποΈ Pipeline

The MLOps (Machine Learning Operations) pipeline project is designed to create an end-to-end workflow for developing and deploying a web application that performs data preprocessing, model training, model evaluation, and prediction. The pipeline leverages Docker containers for encapsulating code, artifacts, and both the frontend and backend components of the application. The application is deployed on a Streamlit to provide a cloud hosting solution.
The pipeline follows the following sequence of steps:
**Data Ingestion**: The pipeline starts with the input data, which is sourced from a specified location. It can be in the form of a CSV file.
**Preprocessing:** The data undergoes preprocessing steps to clean, transform, and prepare it for model training. This stage handles tasks such as missing value imputation, feature scaling, and categorical variable encoding.
**Model Training:** The preprocessed data is used to train machine learning models. The pipeline supports building multiple models, allowing for experimentation and comparison of different algorithms or hyperparameters.
**Model Evaluation:** The trained models are evaluated using appropriate evaluation metrics to assess their performance. This stage helps in selecting the best-performing model for deployment.
**Docker Container:** The pipeline utilizes Docker containers to package the application code, model artifacts, and both the frontend and backend components. This containerization ensures consistent deployment across different environments and simplifies the deployment process.
**Streamlit:** The Docker container, along with the required dependencies, is deployed on a droplet Streamlit. Streamlit provides a cloud hosting solution that allows for scalability, reliability, and easy management of the web application.
**Web App:** The web application is accessible via a web browser, providing a user-friendly interface for interacting with the prediction functionality. Users can input new data and obtain predictions from the deployed model.
**Prediction:** The deployed model uses the input data from the web application to generate predictions. These predictions are then displayed to the user via the web interface.
**Evidently AI :** A tools for model monitering and data drifting detection when new data comes in.
**CI/CD Pipeline:** The pipeline is automated using GitHub Actions, which allows for continuous integration and deployment of the application. This automation ensures that the application is always up-to-date and provides a consistent experience for users.
### πΉοΈ Streamlit App
There is a live demo of this project using Streamlit which you can find [here](https://end-to-end-customer-churn-prediction-9en8mwgk9xqgy8z7envfmm.streamlit.app/)
## Video
## Project Video
Check out the demo of my project on YouTube: [Watch Video](https://youtu.be/Nj-ICiTPJYA?si=EUfhNkFQ3PF47V25) below
[](https://youtu.be/Nj-ICiTPJYA?si=EUfhNkFQ3PF47V25)
<if
## Data Report
### Data Drift Detection using Evidently ai



## Classification Perfomance using Evidently AI


 |