Customer Churn & Retention Intelligence is an end-to-end machine learning project that predicts customer churn risk and provides practical retention recommendations.
The system takes customer data, generates a churn probability and risk level, and suggests potential retention actions for individual customers.
The project combines machine learning with a customer-facing Streamlit application, SQLite storage, FastAPI and Power BI to demonstrate the full workflow from prediction to business use.
Three classification models were evaluated on the held-out test set.
| Model | Accuracy | Precision | Recall | F1 | ROC-AUC | PR-AUC |
|---|---|---|---|---|---|---|
| Logistic Regression | 80.06% | 58.35% | 86.90% | 69.82% | 90.99% | 79.34% |
| Random Forest | 84.17% | 68.37% | 75.13% | 71.59% | 90.86% | 78.50% |
| XGBoost | 86.02% | 76.74% | 67.91% | 72.06% | 91.56% | 81.27% |
XGBoost was selected as the final model based on its strongest overall performance across the evaluation metrics.
The classification threshold was set to 0.40 to provide a practical precision/recall trade-off for retention outreach.
| Threshold | Precision | Recall | F1 | Customers Flagged |
|---|---|---|---|---|
| 0.30 | 66.23% | 81.28% | 72.99% | 459 |
| 0.40 | 71.32% | 73.80% | 72.54% | 387 |
| 0.50 | 76.74% | 67.91% | 72.06% | 331 |
| 0.60 | 81.18% | 62.30% | 70.50% | 287 |
| 0.70 | 86.34% | 52.41% | 65.22% | 227 |
The 0.40 threshold is an initial operational choice rather than a cost-optimized business threshold, since intervention costs and customer value were not available.
The Streamlit dashboard provides an operational view of individual customer churn risk, including churn probability, risk level, customer details and recommended retention actions.
The Power BI dashboard provides a high-level view of churn patterns across contracts, tenure, internet type, monthly charges and payment methods.
- Python — Core development and machine learning
- Pandas / NumPy — Data processing and analysis
- Scikit-learn — Preprocessing and Logistic Regression / Random Forest
- XGBoost — Final churn prediction model
- Joblib — Model and preprocessing artifact serialization
- SQLite — Customer data storage
- Streamlit — Customer-facing churn dashboard
- FastAPI / Uvicorn — Prediction API
- Power BI — Business analytics and visualization
- Docker — Application containerization
Windows PowerShell:
python -m venv .venv
.venv\Scripts\Activate.ps1pip install -r requirements.txtstreamlit run frontend/app.pyIn a separate terminal:
uvicorn api.app:app --reloadAPI documentation:
http://127.0.0.1:8000/docs
docker build -t customer-churn-retention .docker run -d -p 8000:8000 --name customer-churn-api customer-churn-retentionThe FastAPI service will be available at:
http://127.0.0.1:8000
Swagger documentation:
http://127.0.0.1:8000/docs
The system does not use another machine learning model to decide what action to take.
Instead, it combines the customer's churn risk with a small set of customer characteristics and applies simple business rules.
For example:
- Month-to-month contract → suggest a longer-term contract with an appropriate incentive.
- High monthly charge → suggest reviewing the customer's plan or pricing.
- Short tenure → suggest early-tenure support or a retention offer.
- Fiber internet service → suggest reviewing pricing and service experience.
- No online security → suggest an online security offer.
- No premium tech support → suggest a support offer.
- No referrals → suggest a referral or engagement incentive.
The result is a short list of actions that a retention team can consider for the individual customer.
The recommendations are intentionally transparent and rule-based. They are suggestions based on observed customer attributes, not claims that a particular action will definitely prevent churn.
- The model is trained and evaluated on a single customer churn dataset, so performance may not generalize to other customer populations.
- The 0.40 classification threshold is an initial operational choice and has not been optimized using real intervention costs or customer value.
- Retention recommendations are rule-based suggestions, not causal predictions of which action will actually prevent a customer from churning.
- A churn prediction indicates risk, not certainty or cause. The model does not establish why an individual customer will churn.
- The current system is a portfolio project and has not been evaluated in a live production retention campaign.



