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.
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
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
Since real company data is not available, we simulate realistic customer behavior.
- 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.
- Python
- Pandas, NumPy
- Scikit-learn
- Random Forest Classifier
- Joblib
- FastAPI
- Uvicorn
- Pydantic
- Next.js (React)
- TypeScript
- Tailwind CSS
- Recharts
- Lucide Icons
- VS Code
- Git & GitHub
Customer Data
β
Data Cleaning
β
Feature Engineering
β
Model Training
β
Model Evaluation
β
FastAPI Backend
β
Next.js Dashboard
β
Prediction + Business Actions
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
- Generate synthetic dataset
- Clean & preprocess data
- Encode categorical variables
- Create new features
- Train Random Forest model
- Evaluate model performance
- Save trained model
- Serve predictions via FastAPI
- Display results in dashboard
Why?
β Works well on tabular data β Handles non-linear patterns β Gives feature importance β High accuracy & robust
Metrics used:
- Accuracy
- Precision
- Recall
- F1 Score
- ROC-AUC
- Confusion Matrix
-
High churn customers:
- Low tenure
- High charges
- Low usage
- Many support tickets
-
Important features:
- Support tickets
- Monthly charges
- Tenure
- Usage behavior
| Risk Level | Action |
|---|---|
| High Risk | Offer discount + support call |
| Medium Risk | Personalized retention email |
| Low Risk | Normal engagement |
git clone https://github.com/VaidehiDeore/Customer-Churn-Prediction.git
cd Customer-Churn-Predictionpython -m venv venvActivate:
venv\Scripts\activatepip install -r requirements.txtpython main.pyThis runs:
Data Generation β Preprocessing β Training β Evaluation
$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:appOpen:
http://127.0.0.1:8000
http://127.0.0.1:8000/docs
cd dashboard
npm install
npm run devOpen:
http://localhost:3000
β Premium SaaS-style UI β Customer metrics overview β Churn driver analysis β Risk distribution chart β Custom input prediction β Real-time API integration β Customer watchlist table
- Accuracy: ~85β90%
- Strong recall for churn customers
- Balanced classification performance
- End-to-end ML system building
- Data preprocessing & feature engineering
- Model training & evaluation
- FastAPI deployment
- Next.js frontend integration
- Business-driven AI solutions
- CSV upload for bulk prediction
- Real-time filtering
- Export results
- SHAP explainability
- Database integration
- User authentication
- Cloud deployment (AWS/Vercel)
Vaidehi Deore Second Year Engineering Student
Built for:
- Data Science
- Machine Learning
- Business Analytics
This project demonstrates a complete industry-level pipeline:
β Data β Model β API β Dashboard β Business Action






