Skip to content

App that predicts if an employee will leave or not the company.

Notifications You must be signed in to change notification settings

eeeds/churn-prediction-app

Repository files navigation

Churn-prediction app.

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.

Content

Tools

Dataset

Dataset's link

Enviroment

I'm going to use a conda enviroment for this project called churn-project.

Create the enviroment

conda create -n churn-project python=3.9

Activate the enviroment

conda activate churn-project

Install dependencies

pip install -r requirements.txt

Working on the notebook

Working on notebook: exploratory_analysis.ipynb Follow the notebook to see the results.

Analysis conclusions

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.

Jupyter Notebook into python code

You can transform your notebook into python code by using the command:

jupyter nbconvert --to python exploratory_analysis.ipynb

Flask Application

Install Flask with the command:

pip install flask

Create the app

Working on serve.py

Run the app

python serve.py

Send a request

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'

Front end

I'm going to use a Streamlit.io front end for this project.

Install Streamlit

pip install streamlit

Working on design

Working on front in Front End

Run the app

streamlit run front_end.py

Dockerfile

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" ]

Build the image

docker build -t churn-project .

Run the container

docker run -p 8501:8501 churn-project

Cloud

The application is deployed in Streamlit cloud.

After Course

Trying Gradio

Install gradio with the following command:

pip install gradio

I'll work with the file front_end_alternative.py

Run the app

Run the app with the command:

python front_end_alternative.py

About

App that predicts if an employee will leave or not the company.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published