Skip to content

About

An end-to-end cost-sensitive customer churn prediction system that combines machine learning, business cost optimization, threshold tuning, and an interactive Streamlit dashboard to prioritize customer retention and reduce potential revenue loss.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Ό Cost-Sensitive Customer Churn Prediction

End-to-End Machine Learning System for Customer Retention with Business Cost Optimization

Python Scikit-Learn Streamlit License


πŸ“– Overview

Customer churn is one of the most critical challenges for subscription-based businesses. Instead of focusing solely on prediction accuracy, this project applies cost-sensitive machine learning to optimize business outcomes.

The system identifies customers who are likely to churn, evaluates the financial impact of prediction errors, tunes the classification threshold based on business cost, and provides an interactive dashboard for retention decision-making.


πŸš€ Key Features

  • πŸ“Š Exploratory Data Analysis (EDA)
  • 🧹 Data Cleaning & Preprocessing
  • βš™οΈ Feature Engineering
  • βš–οΈ Class Imbalance Handling
  • πŸ€– Multiple Machine Learning Models
  • 🎯 Threshold Optimization
  • πŸ’° Business Cost Function
  • πŸ“ˆ ROI & Revenue Loss Analysis
  • πŸ“‰ Confusion Matrix Analysis
  • πŸ“Š Interactive Streamlit Dashboard
  • πŸ‘€ Individual Customer Scoring
  • πŸ“‚ Batch Customer Prediction
  • πŸ“‹ Data Quality Dashboard


πŸ“Έ Dashboard Preview

Experience the interactive Streamlit dashboard designed to transform churn predictions into actionable business insights.

🏠 Executive Overview

Monitor customer churn rate, risk distribution, flagged customers, and total CLTV exposure through an executive-friendly dashboard.


πŸ” Risk Explorer

Filter customers by risk level, contract type, and churn probability to generate targeted retention action lists.


πŸ’° Business Impact Dashboard

Compare intervention strategies, estimate financial exposure, optimize retention costs, and evaluate projected savings.


πŸ“Š Model Comparison

Score individual models, predict churn probability, assign risk segments, and support retention decisions.


πŸš€ Threshold and Cost-Optimizer

Optimizes a ML classification threshold to balance missed churners against false alarms, minimizing total financial costs for the business.


πŸŽ₯ Methodology

outlines the data preparation, modeling, and cost-focused evaluation strategy used to build and select the optimal churn prediction system.


πŸ—οΈ Solution Architecture

The solution follows an end-to-end machine learning workflowβ€”from raw customer data ingestion to business-driven retention recommendations delivered through an interactive Streamlit dashboard.


🧠 Machine Learning Pipeline

Raw Customer Data
        β”‚
        β–Ό
Data Cleaning
        β”‚
        β–Ό
Feature Engineering
        β”‚
        β–Ό
Encoding & Scaling
        β”‚
        β–Ό
Class Imbalance Handling
        β”‚
        β–Ό
Train Multiple Models
        β”‚
        β–Ό
Model Evaluation
        β”‚
        β–Ό
Threshold Optimization
        β”‚
        β–Ό
Business Cost Analysis
        β”‚
        β–Ό
Model Deployment (Streamlit)

πŸ† Models Compared

  • Logistic Regression
  • Random Forest
  • XGBoost
  • LightGBM

The best-performing model is selected based on predictive performance and business impact rather than accuracy alone.


πŸ’° Business-Oriented Optimization

Unlike traditional churn prediction projects, this solution evaluates the financial impact of model decisions.

The optimization considers:

  • False Positive Cost
  • False Negative Cost
  • Customer Lifetime Value (CLTV)
  • Decision Threshold Optimization
  • Revenue Loss Estimation
  • Retention ROI

This enables data-driven retention strategies instead of relying on a default 0.5 classification threshold.


πŸ“Š Dashboard Features

The Streamlit application includes:

πŸ“ˆ Executive Overview

  • Customer churn rate
  • Customers flagged for retention
  • CLTV exposure
  • Risk distribution

πŸ” Risk Explorer

  • Filter customers by risk level
  • Contract type analysis
  • Probability threshold filtering
  • Export retention action lists

πŸ‘€ Customer Scoring

  • Predict churn probability for a single customer
  • Risk categorization
  • Retention recommendation

πŸ’° Business Impact

  • Compare intervention strategies
  • Revenue exposure
  • Estimated savings
  • Offer investment analysis

πŸ“‹ Data Quality

  • Missing values
  • Dataset statistics
  • Column summaries
  • Data profiling

πŸ“‚ Project Structure

Cost-Sensitive-Churn-Prediction/
β”‚
β”œβ”€β”€ artifacts/
β”‚   β”œβ”€β”€ churnmodel.pkl
β”‚   β”œβ”€β”€ modelcolumns.pkl
β”‚   β”œβ”€β”€ bestthreshold.pkl
β”‚   └── labelencoders.pkl
β”‚
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ overview.png
β”‚   β”œβ”€β”€ risk-explorer.png
β”‚   β”œβ”€β”€ customer-scoring.png
β”‚   β”œβ”€β”€ business-impact.png
β”‚   β”œβ”€β”€ data-quality.png
β”‚   β”œβ”€β”€ model-pipeline.png
β”‚   └── demo.gif
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/
β”‚   └── processed/
β”‚
β”œβ”€β”€ notebooks/
β”‚   └── churn_prediction.ipynb
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
β”œβ”€β”€ LICENSE
└── .gitignore

βš™οΈ Installation

Clone the repository

git clone https://github.com/yourusername/Cost-Sensitive-Churn-Prediction.git

Move into the project

cd Cost-Sensitive-Churn-Prediction

Install dependencies

pip install -r requirements.txt

▢️ Run the Dashboard

streamlit run app.py

πŸ“ˆ Dataset

This project uses the Telco Customer Churn Dataset, which contains customer demographics, subscription information, service usage, billing details, and churn labels.

Key attributes include:

  • Customer Demographics
  • Contract Information
  • Internet Services
  • Payment Methods
  • Monthly Charges
  • Total Charges
  • Customer Lifetime Value (CLTV)
  • Churn Status

🎯 Skills Demonstrated

  • Machine Learning
  • Classification
  • Cost-Sensitive Learning
  • Business Analytics
  • Feature Engineering
  • Threshold Optimization
  • Model Evaluation
  • Hyperparameter Tuning
  • Streamlit
  • Data Visualization
  • Business Intelligence

πŸš€ Future Improvements

  • SHAP Explainability
  • Customer Segmentation
  • AutoML Integration
  • MLflow Experiment Tracking
  • Docker Deployment
  • Cloud Deployment (AWS/Azure)
  • Real-Time Prediction API
  • Drift Monitoring
  • Customer Recommendation Engine

⭐ Support

If you found this project helpful, consider giving it a Star ⭐.

Feedback, suggestions, and contributions are always welcome.

About

An end-to-end cost-sensitive customer churn prediction system that combines machine learning, business cost optimization, threshold tuning, and an interactive Streamlit dashboard to prioritize customer retention and reduce potential revenue loss.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages