Bank Customer Analytics and Churn Prediction
This project analyzes bank customer data to understand customer behavior, perform segmentation, and predict customer churn using machine learning. It demonstrates an end-to-end data analytics and machine learning workflow, including data preprocessing, feature engineering, model training, and API-based deployment.
Project Objectives
Analyze customer demographics and financial behavior
Identify churn patterns and high-risk customer segments
Build a churn prediction model using machine learning
Deploy the trained model through a REST API for real-time predictions
Provide data-driven business recommendations for customer retention
Setup
-
Create a virtual environment python -m venv venv
-
Activate the environment
Windows
venv\Scripts\activate
macOS / Linux
source venv/bin/activate
- Install dependencies pip install -r requirements.txt
Machine Learning Approach
Target variable: churn
Model: Logistic Regression
Preprocessing
One-Hot Encoding for categorical features
Standard Scaling for numerical features
Feature Engineering
Age segmentation (age_group)
Balance indicator (has_balance)
All preprocessing and modeling steps are encapsulated in a scikit-learn Pipeline to ensure consistency between training and inference.
Model Training
To train and save the model:
python src/train_model.py
The trained model is saved to:
models/churn_model.pkl
API Usage
The trained model is exposed via a FastAPI application.
Run the API uvicorn api.main:app --reload
API Documentation http://127.0.0.1:8000/docs
Example Request { "credit_score": 620, "country": "Germany", "gender": "Male", "age": 46, "tenure": 4, "balance": 95000, "products_number": 1, "credit_card": 1, "active_member": 0, "estimated_salary": 52000 }
Example Response { "churn_probability": 0.527 }
Dashboard
A Power BI dashboard is included to visualize:
Customer segmentation
Churn distribution
Key performance indicators for decision-makers
Business Recommendations
Customers with churn probability above 0.5 should be considered at risk
High-risk segments can be targeted with proactive retention campaigns
Customer activity status, balance, and age are key indicators of churn
Data-driven retention strategies can significantly reduce customer attrition