An end-to-end machine learning system that predicts whether a bank customer will churn โ
built with Neural Networks and deployed as an interactive Streamlit web application.
Customer churn costs banks millions annually. Identifying at-risk customers before they leave allows businesses to take targeted retention actions โ saving revenue and improving customer relationships ๐ฏ
This project answers the question:
"Given a customer's demographic and banking profile, how likely are they to leave?"
- ๐ Project Overview
- ๐ Live Demo
- ๐ Project Structure
- ๐ ๏ธ Tech Stack
- ๐ Dataset Description
- ๐ Key Insights from EDA
- โ๏ธ Data Preprocessing
- ๐ค Model Training & Performance
- ๐ง Neural Network Architecture
- ๐ฎ Inference Pipeline
- ๐ Application Features
โถ๏ธ Run Locally- ๐ก Business Recommendations
- ๐ญ Future Improvements
- ๐ฉโ๐ป Author
Customer-Churn-Prediction/
โ
โโโ app/
โ โโโ app.py # Streamlit web application
โ
โโโ data/
โ โโโ raw/
โ โ โโโ Churn_Modelling.csv # Original dataset
โ โโโ processed/
โ โโโ Churn_processed.csv # Cleaned and encoded dataset
โ
โโโ models/
โ โโโ churn_prediction_model.h5 # Trained Neural Network
โ โโโ scaler.pkl # Fitted StandardScaler
โ โโโ training_columns.pkl # Column list for consistent inference
โ
โโโ notebooks/
โ โโโ churn_analysis.ipynb # Full analysis notebook
โ
โโโ src/
โ โโโ preprocessing.py # Data loading and preprocessing functions
โ โโโ train_model.py # Model building and training functions
โ โโโ evaluate.py # Model evaluation functions
โ
โโโ requirements.txt
โโโ README.md
| ๐ท๏ธ Category | ๐ง Tools |
|---|---|
| ๐ Language | Python 3.11 |
| ๐ง Deep Learning | TensorFlow, Keras |
| ๐ ML & Data | Scikit-learn, Pandas, NumPy |
| ๐ Visualization | Matplotlib, Seaborn |
| ๐ Deployment | Streamlit |
| ๐พ Model Serialisation | Joblib |
The dataset used is the Credit Card Customer Churn dataset from Kaggle.
- Total Records: 10,000 customers
- Features: 14 columns (
RowNumber,CustomerId,Surnamedropped before modelling) - Target Variable:
Exited(1 = Churned, 0 = Stayed) - Class Distribution: 79.6% Stayed / 20.4% Churned โ handled via class weights
| ๐ Feature | ๐ Description |
|---|---|
CreditScore |
๐ณ Customer credit score |
Geography |
๐ Customer location (France, Germany, Spain) โ one-hot encoded |
Gender |
๐ค Male / Female โ one-hot encoded |
Age |
๐ Customer age |
Tenure |
๐ Years with bank |
Balance |
๐ฐ Account balance |
NumOfProducts |
๐ฆ Number of bank products |
HasCrCard |
๐ณ Has credit card (1 = Yes, 0 = No) |
IsActiveMember |
โ Active member status (1 = Yes, 0 = No) |
EstimatedSalary |
๐ต Customer estimated salary |
| ๐ Insight | ๐ผ Business Implication |
|---|---|
| ๐ 20.4% overall churn rate | Significant revenue at risk โ retention efforts needed |
| ๐ Germany has highest churn | Target German customers with special retention offers |
| ๐ด Age 50โ60 has 56.2% churn rate | Highest risk group โ prioritise retention for middle-aged customers |
| ๐ง Age 40โ50 has 34.0% churn rate | Second highest risk group โ early intervention recommended |
| ๐ง Age <30 has only 7.5% churn rate | Most loyal segment โ leverage for referrals and upselling |
| ๐ข Step | โ๏ธ Detail |
|---|---|
| ๐๏ธ Drop columns | RowNumber, CustomerId, Surname removed |
| ๐ค One-Hot Encoding | Geography and Gender encoded using pd.get_dummies(drop_first=True) |
| ๐พ Column list saved | training_columns.pkl saved to ensure consistent inference |
| โ๏ธ Train-Test Split | 80% train / 20% test, random state = 1 |
| ๐ Feature Scaling | StandardScaler โ fit_transform on train, transform on test |
Multiple models were evaluated with class_weight='balanced' applied to handle the 80/20 class imbalance.
| ๐ค Model | ๐ฏ Accuracy |
|---|---|
| ๐ Logistic Regression | ~72% |
| ๐ณ Decision Tree | ~76% |
| โ Neural Network | ~80% |
The Neural Network was selected as the final model as it significantly outperforms the baseline models and captures complex, non-linear patterns in customer behaviour that simpler models miss. Decision Trees tend to overfit, and Logistic Regression assumes linear relationships โ both limitations the Neural Network overcomes with its layered architecture and Dropout regularisation.
Fig 4 โ (Top) Training vs Validation Loss & Accuracy over 50 epochs ย |ย (Bottom) Confusion Matrix & Permutation Feature Importance
The model converges steadily across 50 epochs with no signs of overfitting. The confusion matrix confirms strong performance on the majority class, while the permutation feature importance chart reveals that NumOfProducts and Age are the most influential predictors of churn.
| ๐๏ธ Layer | โ๏ธ Configuration |
|---|---|
| โก๏ธ Input Layer | 11 features |
| ๐ต Dense Layer | 64 neurons (ReLU) |
| ๐ Dropout | 0.3 |
| ๐ต Dense Layer | 32 neurons (ReLU) |
| ๐ Dropout | 0.3 |
| ๐ฏ Output Layer | 1 neuron (Sigmoid) |
| โก Training Config | ๐ Value |
|---|---|
| ๐ Loss Function | Binary Crossentropy |
| โ๏ธ Optimizer | Adam |
| ๐ Epochs | 50 |
| ๐ฆ Batch Size | 32 |
| โ๏ธ Class Weights | Applied to address 80/20 imbalance |
At inference time three saved assets are loaded:
churn_prediction_model.h5โ the trained neural networkscaler.pklโ the fittedStandardScalertraining_columns.pklโ the exact column list after one-hot encoding
This guarantees new customer data is encoded identically to how the training data was processed โ no silent column mismatches.
The deployed Streamlit dashboard includes:
- ๐๏ธ Customer Input Panel โ credit score, age, tenure, balance, number of products, credit card status, active membership, estimated salary, geography, and gender
- ๐ค Real Model Inference โ predictions from the trained neural network
- ๐ฆ Three Risk Tiers โ High (>50%), Medium (30โ50%), Low (<30%) with visual progress bar
- ๐ก Retention Suggestions โ contextual tips based on the customer's specific risk factors
# 1. Clone the repository
git clone https://github.com/mysticalayushi/Customer-Churn-Prediction.git
cd Customer-Churn-Prediction
# 2. Install dependencies
pip install -r requirements.txt
# 3. Launch the Streamlit app
streamlit run app/app.pyOr explore the analysis notebook:
jupyter notebook notebooks/churn_analysis.ipynb- ๐ฏ Target German customers with special retention offers as they show higher churn probability
- ๐ค Engage inactive members through loyalty programs, personalised emails, or incentives
- ๐ด Focus on customers aged 50โ60 as this group has the highest churn rate at 56.2%
- ๐ง Monitor customers aged 40โ50 as they represent the second highest risk group at 34.0%
- ๐ Introduce personalised financial products based on customer behaviour and risk score
- ๐ฒ Improve model performance using Gradient Boosting or XGBoost
- ๐ง Perform hyperparameter tuning to further optimise prediction accuracy
- ๐ Incorporate additional customer behaviour features such as transaction frequency
- ๐งช Implement A/B testing strategies to evaluate churn reduction campaigns
- โก Build a real-time data pipeline for automated churn monitoring
- ๐ Add SHAP values for deeper model explainability
| ๐ Field | ๐ Detail |
|---|---|
| ๐ฉโ๐ป Created by | Ayushi Rai |
| ๐ง Model | Neural Network (TensorFlow / Keras) |
| ๐ฏ Test Accuracy | ~80% |
| ๐ Dataset | Credit Card Customer Churn โ Kaggle (10,000 records) |
| ๐ Date | March 2026 |


