A full-stack machine learning platform for predicting customer churn in telecom services, featuring three different ML models, real-time predictions, bulk CSV processing, and comprehensive analytics.
- Real-time Predictions: Instant churn probability with risk assessment
- Three ML Models: Compare PyCaret LR, H2O AutoML, and Gradient Boosting Ensemble
- Bulk CSV Upload: Process thousands of customers at once
- Model Comparison: Side-by-side performance metrics and graphs
- Prediction History: Track and analyze past predictions with filtering
- Analytics Dashboard: Feature importance, churn patterns, and insights
- Premium UI: Netflix-inspired design with glassmorphism effects
- Serverless Architecture: Deployed on Vercel with zero-config
- React 18 with TypeScript
- Vite for blazing-fast builds
- TailwindCSS for styling
- React Router for navigation
- Lucide Icons for UI elements
- FastAPI for serverless API endpoints
- PyCaret for automated ML
- H2O AutoML for ensemble models
- XGBoost, LightGBM, CatBoost for gradient boosting
- Pandas for data processing
- Supabase (PostgreSQL) for prediction storage
- Vercel for frontend and serverless functions
- GitHub for version control
churn-prediction-ai/
├── src/ # React frontend
│ ├── components/
│ │ └── Navbar.tsx # Navigation with glassmorphism
│ ├── pages/
│ │ ├── Dashboard.tsx # Overview with stats
│ │ ├── Predict.tsx # Single prediction form
│ │ ├── Upload.tsx # Bulk CSV upload
│ │ ├── Analytics.tsx # Model comparison & insights
│ │ ├── History.tsx # Prediction history
│ │ └── About.tsx # Project documentation
│ ├── lib/
│ │ ├── api.ts # API client
│ │ └── supabase.ts # Supabase client
│ ├── App.tsx # Main app component
│ └── main.tsx # Entry point
├── api/ # FastAPI serverless functions
│ ├── models.py # Shared ML logic
│ ├── final.py # PyCaret Logistic Regression
│ ├── benchmark.py # H2O AutoML ensemble
│ ├── test.py # XGBoost/LightGBM/CatBoost
│ ├── predict.py # Unified prediction endpoint
│ └── upload.py # Bulk CSV processing
├── notebooks/ # Jupyter notebooks (training)
│ ├── Final.ipynb # PyCaret model training
│ ├── Benchmark.ipynb # H2O AutoML training
│ └── Test.ipynb # Ensemble model training
├── vercel.json # Vercel configuration
├── package.json # Frontend dependencies
├── requirements.txt # Python dependencies
└── README.md # This file
| Endpoint | Method | Description |
|---|---|---|
/api/final |
POST | PyCaret Logistic Regression predictions |
/api/benchmark |
POST | H2O AutoML ensemble predictions |
/api/test |
POST | Gradient Boosting ensemble predictions |
/api/predict |
POST | Unified endpoint (accepts model parameter) |
/api/upload |
POST | Bulk CSV processing with model selection |
| Model | Accuracy | ROC-AUC | Precision | Recall | Approach |
|---|---|---|---|---|---|
| Final | 80.3% | 84.5% | 78.2% | 72.5% | Logistic Regression (PyCaret) |
| Benchmark | 80.0% | 85.1% | 79.1% | 71.8% | Stacked Ensemble (H2O AutoML) |
| Test | 80.2% | 83.5% | 77.8% | 73.2% | XGBoost + LightGBM + CatBoost |
- Node.js 18+ and npm
- Python 3.10+
- Supabase account (free tier)
- Vercel account (optional, for deployment)
- Clone the repository
git clone https://github.com/yourusername/churn-prediction-ai.git
cd churn-prediction-ai- Install frontend dependencies
npm install- Install backend dependencies
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt- Configure environment variables
Create a .env file in the root directory:
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
VITE_API_URL=http://localhost:8000 # For local dev- Set up Supabase database
Run this SQL in your Supabase SQL Editor:
CREATE TABLE predictions (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
gender TEXT,
senior_citizen INTEGER,
partner TEXT,
dependents TEXT,
tenure INTEGER,
phone_service TEXT,
multiple_lines TEXT,
internet_service TEXT,
online_security TEXT,
device_protection TEXT,
tech_support TEXT,
streaming_tv TEXT,
streaming_movies TEXT,
contract_type TEXT,
paperless_billing TEXT,
payment_method TEXT,
monthly_charges NUMERIC,
total_charges NUMERIC,
churn_probability NUMERIC,
risk_level TEXT
);- Run the development servers
Terminal 1 (Frontend):
npm run devTerminal 2 (Backend - optional for local testing):
uvicorn api.predict:app --reload --port 8000Or use Vercel CLI for full-stack local development:
npm i -g vercel
vercel dev- Push to GitHub
git add .
git commit -m "Initial commit"
git push origin main- Deploy to Vercel
- Go to vercel.com/new
- Import your GitHub repository
- Vercel auto-detects Vite + Python
- Add environment variables in Project Settings:
VITE_SUPABASE_URLVITE_SUPABASE_ANON_KEY
- Deploy!
- Navigate to Predict page
- Select ML model (Final/Benchmark/Test)
- Fill in customer details
- Click "Predict Churn"
- View churn probability, risk level, drivers, and retention strategies
- Navigate to Upload page
- Select ML model
- Upload CSV file with customer data
- View batch prediction summary
- Download results
- View model performance comparison
- Analyze feature importance
- Explore churn patterns by tenure, charges, contract type
- Get actionable insights
- View all past predictions
- Filter by risk level
- Search by contract type
- Paginated results
The model uses 18 customer features:
Demographics: Gender, Senior Citizen, Partner, Dependents
Services: Phone Service, Multiple Lines, Internet Service, Online Security, Device Protection, Tech Support, Streaming TV, Streaming Movies
Account: Contract Type, Paperless Billing, Payment Method, Tenure
Financial: Monthly Charges, Total Charges
The three notebooks in the root directory contain the model training code:
Final.ipynb: PyCaret AutoML with Logistic RegressionBenchmark.ipynb: H2O AutoML with stacked ensembleTest.ipynb: Custom ensemble (XGBoost + LightGBM + CatBoost)
To retrain models:
- Open the notebook in Jupyter/Colab
- Load your dataset
- Run all cells
- Export trained models to
api/models.py
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - feel free to use this project for learning or commercial purposes.
- Dataset: Telco Customer Churn (Kaggle)
- UI Inspiration: Netflix
- ML Libraries: PyCaret, H2O, XGBoost, LightGBM, CatBoost
For questions or feedback, please open an issue on GitHub.
Built with ❤️ using React, FastAPI, and Machine Learning