pranav-singh-developer-1/telecom-churn-predictor
๐ AI Customer Churn Intelligence (Milestone 1)
This repository contains the Mid-Semester submission for the Customer Churn Prediction & Agentic Retention Strategy project.
Phase 1 focuses entirely on building a robust, production-ready predictive analytics system using Traditional Machine Learning. It analyzes historical behavioral data to identify customers at risk of canceling their service.
๐ State-of-the-Art (SOTA) Features
To move beyond basic templates, this pipeline implements several advanced ML techniques:
๐ Explainable AI (XAI)
Mathematically extracts feature weights to explain why a customer is churning (e.g., high customer service calls), rather than just outputting a black-box probability.
๐ฏ Cost-Sensitive Threshold Tuning
Optimizes the decision boundary from the default 50% to a custom 30% threshold, prioritizing detection of high-risk customers over raw accuracy.
โ๏ธ SMOTE Integration
Utilizes the imbalanced-learn library to generate synthetic data for the minority class (churners), ensuring the Logistic Regression model learns balanced behavioral patterns.
๐งฉ Custom Scikit-Learn Pipelines
Encapsulates data cleaning, dynamic StandardScaler scaling, and OneHotEncoder categorical handling directly into the model artifact.
๐ Repository Architecture
The codebase follows industry-standard modular design for machine learning projects:
churn_project/
โโโ data/ # Ignored in version control
โ โโโ raw/ # Location for telecom_churn.csv
โโโ models/
โ โโโ churn_model.pkl # Serialized ML pipeline artifact
โโโ src/ # Core engine logic
โ โโโ __init__.py
โ โโโ data_loader.py # Data validation script
โ โโโ preprocessing.py # Custom Scikit-Learn Transformer
โ โโโ train_model.py # Pipeline construction and training
โโโ app.py # Gradio + Plotly interactive UI
โโโ requirements.txt # Pinned dependencies for reproducible builds
โโโ README.md # Project documentation๐ ๏ธ Setup & Execution Instructions
Follow the steps below to reproduce the full training and deployment workflow.
1๏ธโฃ Environment Setup
Clone the repository and install dependencies:
git clone https://github.com/Pranav-Singh-Devloper/telecom_churn_prediction.git
cd telecom_churn_prediction
pip install -r requirements.txtIt is recommended to use a virtual environment:
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows2๏ธโฃ Data Preparation
- Download the Telecom Churn dataset.
- Rename the dataset file to:
telecom_churn.csv- Place it inside:
data/raw/Expected structure:
data/
โโโ raw/
โโโ telecom_churn.csv3๏ธโฃ Train the Model
Run the training pipeline:
python src/train_model.pyThis will:
- Apply preprocessing and feature engineering
- Perform SMOTE-based class balancing
- Train the Logistic Regression model
- Optimize the classification threshold
- Generate explainability metrics
- Serialize the trained pipeline
After successful execution, the following file will be created:
models/churn_model.pkl4๏ธโฃ Launch the Interactive Dashboard
Start the Gradio application:
python app.pyThen open your browser and navigate to:
http://127.0.0.1:7860The dashboard allows you to:
- Input customer attributes
- Generate churn probability predictions
- View explainability insights
- Interactively analyze risk factors
๐ Complete Workflow Summary
- Install dependencies
- Place dataset in
data/raw/ - Train model (
train_model.py) - Launch UI (
app.py)
Your churn intelligence system is now fully operational.
