Skip to content

VaidehiDeore/Customer-Churn-Prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Customer Churn Prediction System (AI-Powered)

An end-to-end Machine Learning + Full Stack project that predicts customer churn, explains risk, and recommends retention actions using a FastAPI backend and a premium Next.js dashboard UI.


πŸ“Œ Project Overview

Customer churn refers to customers who stop using a product/service. For subscription-based businesses (telecom, SaaS, OTT, fintech), churn directly impacts revenue and growth.

This project builds a complete churn prediction system that:

  • Predicts whether a customer will churn
  • Calculates churn probability
  • Categorizes risk level (High / Medium / Low)
  • Suggests business actions to retain customers
  • Visualizes insights in an interactive dashboard

🎯 Problem Statement

Companies often lose customers because they identify churn too late.

This system solves that by:

βœ” Predicting churn in advance βœ” Identifying high-risk customers βœ” Helping teams take proactive action βœ” Improving retention and revenue


🧠 How Churn Simulation Works

Since real company data is not available, we simulate realistic customer behavior.

Customers are more likely to churn when:

  • Low tenure (new customers)
  • High monthly charges
  • Low product usage
  • High support tickets
  • Payment delays
  • No autopay enabled
  • Month-to-month contracts

πŸ‘‰ This creates a pattern-based dataset, not random β€” similar to real business scenarios.


βš™οΈ Tech Stack

πŸ”Ή Machine Learning

  • Python
  • Pandas, NumPy
  • Scikit-learn
  • Random Forest Classifier
  • Joblib

πŸ”Ή Backend

  • FastAPI
  • Uvicorn
  • Pydantic

πŸ”Ή Frontend

  • Next.js (React)
  • TypeScript
  • Tailwind CSS
  • Recharts
  • Lucide Icons

πŸ”Ή Tools

  • VS Code
  • Git & GitHub

πŸ—οΈ Project Architecture

Customer Data
     ↓
Data Cleaning
     ↓
Feature Engineering
     ↓
Model Training
     ↓
Model Evaluation
     ↓
FastAPI Backend
     ↓
Next.js Dashboard
     ↓
Prediction + Business Actions

πŸ“ Folder Structure

Customer-Churn-Prediction/
β”‚
β”œβ”€β”€ api/
β”‚   └── main.py                # FastAPI backend
β”‚
β”œβ”€β”€ dashboard/
β”‚   └── app/
β”‚       └── page.tsx           # Next.js dashboard UI
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/
β”‚   β”‚   └── customer_churn_data.csv
β”‚   └── processed/
β”‚       └── processed_churn_data.csv
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ generate_data.py
β”‚   β”œβ”€β”€ preprocess.py
β”‚   β”œβ”€β”€ train_model.py
β”‚   β”œβ”€β”€ evaluate_model.py
β”‚   └── predict.py
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ churn_model.pkl
β”‚   └── model_columns.pkl
β”‚
β”œβ”€β”€ outputs/
β”‚   └── metrics.txt
β”‚
β”œβ”€β”€ images/
β”‚   β”œβ”€β”€ dashboard_home.png
β”‚   β”œβ”€β”€ prediction_result.png
β”‚   β”œβ”€β”€ customer_watchlist.png
β”‚   β”œβ”€β”€ api_docs.png
β”‚   β”œβ”€β”€ confusion_matrix.png
β”‚   β”œβ”€β”€ roc_curve.png
β”‚   └── feature_importance.png
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ main.py
└── .gitignore

πŸ§ͺ Machine Learning Pipeline

Step-by-step:

  1. Generate synthetic dataset
  2. Clean & preprocess data
  3. Encode categorical variables
  4. Create new features
  5. Train Random Forest model
  6. Evaluate model performance
  7. Save trained model
  8. Serve predictions via FastAPI
  9. Display results in dashboard

πŸ€– Model Used

Random Forest Classifier

Why?

βœ” Works well on tabular data βœ” Handles non-linear patterns βœ” Gives feature importance βœ” High accuracy & robust


πŸ“Š Model Evaluation

Metrics used:

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • ROC-AUC
  • Confusion Matrix

πŸ“ˆ Key Insights

  • High churn customers:

    • Low tenure
    • High charges
    • Low usage
    • Many support tickets
  • Important features:

    • Support tickets
    • Monthly charges
    • Tenure
    • Usage behavior

πŸ”₯ Retention Strategy Logic

Risk Level Action
High Risk Offer discount + support call
Medium Risk Personalized retention email
Low Risk Normal engagement

⚑ How to Run the Project


1️⃣ Clone Repository

git clone https://github.com/VaidehiDeore/Customer-Churn-Prediction.git
cd Customer-Churn-Prediction

2️⃣ Create Virtual Environment

python -m venv venv

Activate:

venv\Scripts\activate

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Run Full ML Pipeline

python main.py

This runs:

Data Generation β†’ Preprocessing β†’ Training β†’ Evaluation

5️⃣ Start FastAPI Backend

$env:OPENBLAS_NUM_THREADS="1"
$env:OMP_NUM_THREADS="1"
$env:MKL_NUM_THREADS="1"
$env:NUMEXPR_NUM_THREADS="1"

python -m uvicorn api.main:app

Open:

http://127.0.0.1:8000
http://127.0.0.1:8000/docs

6️⃣ Start Dashboard

cd dashboard
npm install
npm run dev

Open:

http://localhost:3000

πŸ–₯️ Dashboard Features

βœ” Premium SaaS-style UI βœ” Customer metrics overview βœ” Churn driver analysis βœ” Risk distribution chart βœ” Custom input prediction βœ” Real-time API integration βœ” Customer watchlist table


πŸ“Έ Screenshots

Dashboard

Dashboard

Prediction Result

Prediction

Customer Watchlist

Watchlist

API Docs

API

Model Evaluation

Confusion ROC Feature


πŸ“¦ Model Results

  • Accuracy: ~85–90%
  • Strong recall for churn customers
  • Balanced classification performance

🧠 Key Learnings

  • End-to-end ML system building
  • Data preprocessing & feature engineering
  • Model training & evaluation
  • FastAPI deployment
  • Next.js frontend integration
  • Business-driven AI solutions

πŸš€ Future Improvements

  • CSV upload for bulk prediction
  • Real-time filtering
  • Export results
  • SHAP explainability
  • Database integration
  • User authentication
  • Cloud deployment (AWS/Vercel)

πŸ‘©β€πŸ’» Author

Vaidehi Deore Second Year Engineering Student

Built for:

  • Data Science
  • Machine Learning
  • Business Analytics

⭐ Final Note

This project demonstrates a complete industry-level pipeline:

βœ” Data β†’ Model β†’ API β†’ Dashboard β†’ Business Action


About

AI-powered customer churn prediction system with ML model, FastAPI backend, and Next.js dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors