This project has been created to predict the churn of a customer and it's part of a challenge called Project-of-the-week that is being held by Datatalks.club.
- Churn-prediction app.
- Content
- Tools
- Dataset
- Enviroment
- Working on the notebook
- Flask Application
- Front end
- Dockerfile
- Cloud
- After Course
I'm going to use a conda enviroment for this project called churn-project
.
conda create -n churn-project python=3.9
conda activate churn-project
pip install -r requirements.txt
Working on notebook: exploratory_analysis.ipynb Follow the notebook to see the results.
I tested three models:
- Logistic Regression
- Random Forest
- XGBoost
Values | Model | Precision | Recall | f1-score |
---|---|---|---|---|
0 | Logistic Regression | 0.83 | 0.96 | 0.89 |
1 | Logistic Regression | 0.61 | 0.22 | 0.32 |
0 | Random Forest | 0.88 | 0.96 | 0.92 |
1 | Random Forest | 0.77 | 0.50 | 0.61 |
0 | XGBoost | 0.89 | 0.95 | 0.91 |
1 | XGBoost | 0.72 | 0.53 | 0.61 |
Random Forest and XGBoost have performed better than Logistic Regression and they have the same f1-score.
You can transform your notebook into python code by using the command:
jupyter nbconvert --to python exploratory_analysis.ipynb
Install Flask with the command:
pip install flask
python serve.py
I've created a simple script called serve_test.py
that sends a request to the app and prints the response
with this values:
REQUEST={
"CreditScore": 597,
"Geography": "Germany",
"Gender": "Female",
"Age": 35,
"Tenure": 8,
"Balance": 131101.04,
"NumOfProducts": 1,
"HasCrCard": 1,
"IsActiveMember": 1,
"EstimatedSalary": 192852.67,
"Exited": 0
}
URL='http://localhost:9696/predict'
I'm going to use a Streamlit.io front end for this project.
pip install streamlit
Working on front in Front End
streamlit run front_end.py
FROM python:3.9.12
LABEL Author, Esteban Encina
WORKDIR /app
COPY requirements.txt ./requirements.txt
## Install dependencies
RUN pip install -r requirements.txt
## Expose the port
EXPOSE 8501
COPY . /app
## Run the app
ENTRYPOINT [ "streamlit" , "run"]
CMD [ "app.py" ]
docker build -t churn-project .
docker run -p 8501:8501 churn-project
The application is deployed in Streamlit cloud.
Trying Gradio
Install gradio with the following command:
pip install gradio
I'll work with the file front_end_alternative.py
Run the app with the command:
python front_end_alternative.py