Skip to content

About

This project uses machine learning to predict customer churn in the Banking sector. It covers the end-to-end process, from data ingestion, validation, and transformation to model training and deployment using FastAPI. The system includes real-time predictions and provides an API for customer churn analysis.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

54 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Customer Churn Prediction Pipeline (End-to-End ML Project)

CI Python 3.11 Docker MLflow License: MIT

This project demonstrates a full-scale machine learning pipeline to predict customer churn using Python, scikit-learn, XGBoost, and MLflow. It includes data ingestion, validation, transformation, model training, evaluation, and deployment via FastAPI.


๐Ÿš€ Key Features

โœ… Modularized ML Pipeline using OOP & Configurations
โœ… Automated Logging via Python's logging and MLflow
โœ… Baseline model comparison (RandomForest, XGBoost, LogisticRegression, etc.)
โœ… Advanced metrics: Top-Decile Lift, Overfitting Warning
โœ… SHAP-based model explainability
โœ… FastAPI for real-time inference API


๐Ÿ› ๏ธ Project Structure

Churn_Pred/
โ”œโ”€โ”€ components/              # Data ingestion, validation, transformation modules
โ”œโ”€โ”€ entity/                  # Artifact data classes
โ”œโ”€โ”€ logger/                  # Logging module
โ”œโ”€โ”€ exception/               # Custom exception handling
โ”œโ”€โ”€ utils/                   # Utility functions
โ”œโ”€โ”€ artifacts/               # Outputs: models, reports, metrics
โ”œโ”€โ”€ app/                     # FastAPI app for deployment
โ”œโ”€โ”€ main.py                  # Training pipeline entry point
โ”œโ”€โ”€ mlruns/                  # MLflow tracking
โ””โ”€โ”€ README.md

๐Ÿ” ML Pipeline Flow

๐Ÿ“ฆ Data Ingestion โ†’ โœ… Validation โ†’ ๐Ÿ”„ Transformation โ†’ ๐Ÿ”ง Model Training โ†’ ๐Ÿ“ˆ Evaluation โ†’ ๐ŸŒ FastAPI

๐Ÿ” Pipeline Stages

๐Ÿ“ฆ Data Ingestion

  • Reads raw data and drops irrelevant columns (e.g., IDs, names)
  • Splits into training and test sets

โœ… Data Validation

  • Checks schema consistency, missing values, and data drift
  • Ensures all required columns are present

๐Ÿ”„ Data Transformation

  • Applies ColumnTransformer pipelines for numeric and categorical features
  • Saves:
    • .npy arrays (for model training)
    • .csv DataFrames (for debugging)
    • preprocessor.pkl (for deployment reuse)

๐Ÿ”ง Model Training

  • Trains baseline models (RandomForest, XGBoost, LogisticRegression, etc.)
  • Evaluates using:
    • F1 Score
    • ROC AUCROC
    • Top-Decile Lift
    • Feature Importance Feature Importance
  • Tracks all experiments via MLflow
  • Selects and saves the best-performing model

๐ŸŒ API Deployment

  • Exposes real-time inference endpoint using FastAPI
  • API UI available at: http://localhost:8000/
  • Can be containerized via Docker for scalable deployment

๐Ÿ“Š Metrics Tracked

  • Accuracy, F1 Score, Precision, Recall
  • ROC AUC
  • Cross-validation F1 score (mean & std)
  • Top-Decile Lift
  • Overfitting/Underfitting Warnings

๐Ÿ“ฆ Installation

pip install -r requirements.txt

๐Ÿงช Train the Pipeline

python main.py

๐ŸŒ Running API Server

uvicorn app:app --reload

Access App at: http://localhost:8000



๐Ÿ“ Artifacts & Logs

  • Metrics, plots, confusion matrices
  • Trained models stored in: artifacts/model_trained
  • MLflow dashboard: http://localhost:5000 (in terminal mlflow ui)

Steps to View the MLflow Dashboard Locally:

1. Start MLflow UI:

  • Open a terminal (or command prompt).

  • Navigate to your project folder (e.g., Churn_Pred).

  • Run the command:

    mlflow ui

2. Access the Dashboard:

  • Open a browser and go to http://localhost:5000 MLflow Dashboard
  • This will open the MLflow UI where you can see all of your logged experiments, parameters, metrics, and models.

๐Ÿ“ธ Example Output

conf_matrix


๐Ÿ’ก SMOTETomek Explainability

SMOTETomek is a powerful tool to address class imbalance by both increasing the minority class size and cleaning up the dataset by removing noisy or borderline examples. By doing so, it enables models to perform better in imbalanced settings, leading to improved generalization and more accurate predictions. It is especially useful in tasks like fraud detection, medical diagnosis, and anomaly detection where minority class instances are critical for model performance but are often underrepresented.

Before SMOTETomek After SMOTETomek


๐Ÿง  Best Model

The best model after hypertuning was XgBoost is selected based on F1 Score = 0.621, Test Accuracy: 0.85, Train Accuracy: 0.857, ROC AUC: 0.859 , Training time ~40 sec and saved for deployment.


๐Ÿ”ฎ Future Improvements

  • Arabic language support for UAE telecom market (bilingual churn signals)
  • Real-time Kafka stream ingestion replacing batch CSV pipeline
  • Survival analysis model (time-to-churn, not just binary churn)
  • Customer segmentation clustering + per-segment churn model
  • A/B testing framework for retention intervention strategies

๐Ÿ‘จโ€๐Ÿ’ป Author

Rohit Dusane โ€” ML Engineer & Healthcare AI Specialist ๐Ÿ“ง hello@rohitdusane.dev ๐Ÿ’ผ LinkedIn ๐ŸŒ Portfolio

๐Ÿ“„ License

MIT License โ€” see LICENSE

About

This project uses machine learning to predict customer churn in the Banking sector. It covers the end-to-end process, from data ingestion, validation, and transformation to model training and deployment using FastAPI. The system includes real-time predictions and provides an API for customer churn analysis.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages