Skip to content

This repository contains a machine learning project aimed at predicting whether a bank customer will churn (close their account) based on various features such as credit score, age, tenure, account balance, and product usage.

Notifications You must be signed in to change notification settings

sayedgamal99/Predicting-Bank-Customer-Churn-using-Machine-Learning

Repository files navigation

Bank Churn Cover

Bank Customer Churn Prediction App

Table of Contents

  1. Overview
  2. Project Highlights
  3. Data Analysis and Insights
  4. Features
  5. Project Structure
  6. Getting Started
  7. Usage
  8. Technical Components
  9. Model Performance
  10. Example Scenario
  11. Contributing
  12. License

Overview

The Bank Customer Churn Prediction App is a comprehensive data science project designed to predict customer account closures (churn) using advanced machine learning techniques. This end-to-end solution transforms raw customer data into actionable insights, helping financial institutions proactively manage customer retention.

Project Highlights

  • 🤖 Advanced ML Ensemble: XGBoost, LightGBM, and CatBoost
  • 📊 High Prediction Accuracy: AUC Score of 0.891
  • 🌐 Web Interface: Flask-based predictive application
  • 🐳 Containerized Deployment: Docker support
  • 📈 Comprehensive Data Analysis: In-depth exploratory analysis

Technologies Used

  • Language: Python 3.11.5
  • Core Libraries:
    • Pandas, NumPy
    • Scikit-learn
    • Matplotlib, Seaborn

Web & Deployment

  • Framework: Flask
  • Containerization: Docker

Demonstration

APP screen record

Data Analysis and Insights

Key Findings

  • Churn Rate: 21% of customers in the dataset
  • Geographic Trends:
    • Highest churn rate in Germany
  • Demographic Observations:
    • Females showed higher churn propensity
  • Customer Activity:
    • Non-active members more likely to churn

Feature Engineering Highlights

  • Created Age-Tenure Ratio
  • Developed Active Credit Card Status
  • Implemented targeted encoding strategies

Visualization Insights

  1. Zero-balance accounts have higher churn probability
  2. Credit card ownership minimally impacts churn
  3. Customers with 3-4 products exhibit increased churn risk

Features

Machine Learning

  • Ensemble Classifiers:
    • XGBoost
    • LightGBM
    • CatBoost
  • Advanced preprocessing techniques
  • Hyperparameter optimization

Web Application

  • Intuitive user interface
  • Real-time churn prediction
  • Sample data auto-fill functionality

Deployment

  • Docker containerization
  • Easy-to-use deployment

Project Structure

.
├── README.md                   # Project documentation
├── app/                        # Flask application
│   ├── app.py                  # Main application entry point
│   ├── static/                 # Static web resources
│   │   └── styles.css          # Application styling
│   ├── templates/              # HTML templates
│   │   ├── base.html
│   │   ├── form.html
│   │   └── result.html
│   └── utils.py                # Utility functions
├── models/                     # Machine learning models
│   ├── train.py                # Model training script
│   ├── test.py                 # Model testing script
│   └── model.joblib            # Trained model
├── requirements.txt            # Python dependencies
└── dockerfile                  # Docker configuration

Getting Started

Prerequisites

  • Python 3.10+
  • Docker (optional)
  • pip package manager

Installation

venv

  1. Clone the repository:

    git clone https://github.com/your-username/bank-churn-prediction.git
    cd bank-churn-prediction
  2. Create virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # Unix/macOS
    # or
    .venv\Scripts\activate     # Windows
  3. Install dependencies:

    pip install -r requirements.txt

Docker Deployment

docker

# Build Docker image
docker build -t churn-prediction-app .

# Run container
docker run -p 5000:5000 churn-prediction-app

# OR pull pre-built image
docker pull sayedgamal/churn-prediction-app:latest
docker run -p 5000:5000 sayedgamal/churn-prediction-app:latest

Usage

Web Application

  1. Navigate to http://localhost:5000
  2. Input customer details
  3. Click "Predict" for churn probability

Jupyter Notebook

Explore detailed analysis in bank-customer-churn-prediction-0-891-auc-score.ipynb

Technical Components

  • Preprocessing:
    • Target encoding
    • Feature scaling
    • Custom engineering pipelines
  • Model Training:
    • Ensemble voting mechanism
    • Cross-validation
  • Deployment:
    • Flask web framework
    • Docker containerization

Model Performance

  • AUC Score: 0.891
  • Algorithms: XGBoost, LightGBM, CatBoost

Example Scenario

Feature Value
Age 45
Credit Score 750
Geography Germany
Gender Female
Active Member Yes

etc..

Predicted Churn Probability: 76%

Contributing

Contributions are welcome!

Steps to contribute:

  1. Fork the repository
  2. Create your feature branch
  3. Commit changes
  4. Push to the branch
  5. Create a pull request

Developed with ❤️ by Sayed Gamal

About

This repository contains a machine learning project aimed at predicting whether a bank customer will churn (close their account) based on various features such as credit score, age, tenure, account balance, and product usage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages