Best Flask open-source libraries and packages

Bank_Churn_Project

Project uses ML models (XGBoost, Regression, RandomForest, Neural Networks) to predict bank customer churn. XGBoost led with 86.73% accuracy. Utilized Tableau for visualization, hosted online via Docker, Neon, Flask.
Updated 2 months ago

Bank Churn Analysis and Prediction using Machine Learning Techniques

Table of Contents

  1. Project Overview
  2. Analytics Dashboard (Preview)
  3. Contributions
  4. Final Repository Structure
  5. Bank churn data Overview
  6. Target Audience
  7. Visualisations
  8. Launch
  9. App Server Setup

Project Overview

The bank churn prediction project aims to utilize machine learning techniques to predict whether a bank customer is likely to churn (leave) or remain loyal. And also Tableau was utilized for data visualization to analyze patterns and trends within the dataset, providing valuable insights for model training and interpretation.

The project encompasses several key components:

  1. Data Preparation: The dataset containing relevant features such as credit score, age, tenure, balance, and more was obtained and cleaned using Python. The cleaned data was then stored in a PostgreSQL database on Neon Cloud services.

  2. Machine Learning Model: Various machine learning models, including Logistic Regression, Random Forest, XGBoost, and Neural Network, were trained and evaluated using the dataset. Metrics such as accuracy were used to compare the models, and the best-performing model was selected for deployment.

  3. Flask App: A Flask web application was developed to provide a user-friendly interface for inputting customer data and obtaining churn predictions. The app utilizes the selected machine learning model to make real-time predictions.

  4. Visualization: Tableau was utilized for data visualization to analyze patterns and trends within the dataset, providing valuable insights for model training and interpretation.

  5. API Endpoint: An API endpoint was implemented to allow access to sample data from the Bank Churn database, facilitating further analysis or integration with other systems.

  6. Deployment to the cloud: Used Docker for encapsulating the application with all its dependencies into a uniform package. This package was then deployed to the cloud through fly.io, serving as the hosting platform, and ensuring the application's availability online.

Technologies used

Analytics Dashboard (Preview)

Contributions

  • Rohit

    • [Jupyter Notebook] Cleaning of original Bank Churn dataset
    • [Tableau] Created initial visualizations for presentation
    • Assisted with presentation slides and rehearsal
    • Support during Group meetings and work sessions
  • Talieh

    • [PostgreSQL] Database schema design + setup
    • [Python Flask / SQLAlchemy] Development of Flask to create a web application that can interact with databases, perform computations or predictions, and render results dynamically on a web page.
    • [Cloud-Based App Hosting] Migration of entire project solution to fli.io Cloud
    • [Frontend] Full Web development of Flask Application Landing Page (HTML), visualization page, Ml model pages
    • [Tableau] Additional support with creating visualization in Tableau
    • [Docker] Created docker files to facilitate running the application on the cloud.
  • Michael

    • Regression Model
    • Random Forest Model
    • XGBoost model
    • Explanation of models used/summary of results
  • Simon

    • Neural Network Model
    • Data class imbalance research

Final Repository Structure

├── README.md
├── .gitignore
├── .venv
├── 'Images' Folder
└── 'Machine learning Models' Folder
    ├── 'Neural_Networks' Folder
    ├── 'Random_Forest' Folder
    ├── 'Regression' Folder
    └── 'XGBoost' Folder
└── 'static' Folder
    ├── 'css' Folder
    ├── 'data' Folder
    ├── 'img' Folder
    └── 'js' Folder
└── 'templates' Folder
    ├── homepage.html
    ├── index.html
    ├── ml_model.html
    ├── neural_network_model.html
    ├── random_forest_model.html
    ├── regression_model.html
    ├── visualization.html
    └── xgboost.html
├── app.py
├── requirements.txt
└── XGBoost_model


Bank Churn Dataset Overview

  • id: A unique identifier for each entry.
  • CustomerId: A unique identifier for each customer.
  • Surname: The surname of the customer.
  • CreditScore: The credit score of the customer.
  • Geography: The geographical location of the customer.
  • Gender: The gender of the customer.
  • Age: The age of the customer.
  • Tenure: Number of years the customer has been with the bank.
  • Balance: The bank balance of the customer.
  • NumOfProducts: The number of products the customer has with the bank.
  • HasCrCard: Indicates if the customer has a credit card (1) or not (0).
  • IsActiveMember: Indicates if the customer is an active member (1) or not (0).
  • EstimatedSalary: The estimated salary of the customer.
  • Exited: Indicates if the customer has exited (1) or not (0).

Target Audience

  1. Banking Institutions: This project is particularly useful for banking institutions seeking to reduce customer churn rates. Banks can utilize the machine learning model deployed in the Flask web application to predict which customers are at risk of leaving. By identifying at-risk customers early, banks can implement targeted retention strategies to retain valuable customers and improve overall customer satisfaction.

  2. Marketing and Customer Retention Teams: Marketing and customer retention teams within banking institutions can benefit from the insights provided by this project. They can use the predictions generated by the machine learning model to tailor marketing campaigns and retention efforts towards customers identified as likely to churn. This targeted approach can lead to more effective and cost-efficient retention strategies.

  3. Data Analysts and Data Scientists: Data analysts and data scientists who are interested in predictive analytics and machine learning can also find value in this project. They can explore the dataset, evaluate different machine learning models, and gain insights into feature importance and model performance. Additionally, they can leverage the Flask web application and API endpoint to interact with the machine learning model and explore its predictions.

  4. Business Decision Makers: Business decision makers, such as executives and managers within banking institutions, can use the insights generated by this project to inform strategic decisions. By understanding customer churn patterns and predicting future churn behavior, decision makers can allocate resources more effectively, prioritize customer retention efforts, and ultimately drive business growth and profitability.


Visualisation

Interactive Visualisations

** Interactive Tableau Dashboard**

This Tableau Dashboard contains:

  1.  An interactive histogram that shows the distribution of account balance of the dataset, as well as an interactive area chart that shows the Churn distribution across age range. The visualisations can be altered by clicking the slicer buttons to filter based on which country the user wants to see distribution for:
    

This histogram and area chart can also be filtered based on whether the customer from the dataset ‘churned’ (left the bank), or didn’t churn:

Additionally, the histogram and area chart can be filtered on whether the customer had a credit card with the bank or not.

Whenever these filters are used, the dashboard updates to show the churn rate of the selected portion of the dataset
  1.  Interactive bar charts that show the significance of gender, credit card ownership and active membership versus customer loyalty. These bar charts can also be filtered based on the country selected:
    


Launch

There is no need for installation to view this project. Everything is hosted online thanks to Fli.io.

The link to the interactive dashboard is available on the repo's description. Otherwise, you can click this link here to access it.

This repo also contains the necessary files to run the visualization and database locally. Installation is necessary to host the visualization through localhost.


App Server Setup

  • Add DB Password
    You need to create dbpassword.txt in the project working directory and paste your database password there.
    Note: make sure to NOT commit this file to Git.
  • (Once Only) Add New Virtual Environment
    • Open a new terminal and change directory to project working directory
    • Run below command in your project working directory
      • On macOS and Linux:
        python3 -m venv .venv
      • On Windows:
        python -m venv .venv
  • Activate the virtual environment
    • Run below command in your project working directory
      • On macOS and Linux:
        source .venv/bin/activate
      • On Windows:
        .venv\Scripts\activate
    • Verify Python is correctly configured. Run below command, it should shows path to your .venv directory which python
  • Install Required Python Packages
    • Run below command in your project working directory
      pip install -r requirements.txt