Capstone 1 of 8
Customer churn prediction service
Business requirement
A subscription business wants a daily list of customers most likely to cancel, plus a live score on the customer-care screen, so the retention team can call the right people first.
Lessons to finish first
Architecture
- Synthetic customer table (CSV)
- Feature pipeline (tenure, charges, support calls, plan)
- Baseline and two candidate models
- Evaluation on a frozen test set (recall, precision, AUC)
- Saved model with version
- Prediction API (/health, /predict) and nightly batch scoring
Build steps
- Generate 5,000 synthetic customers with a churn rate near 20% and save them as CSV.
- Explore the data: churn rate by plan, tenure and number of support calls.
- Build the majority-class baseline and record its accuracy (it will look high; explain why it is useless).
- Train logistic regression and gradient boosting; compare on the same test set using recall and AUC.
- Choose a decision threshold from the cost of a missed churner versus an unnecessary call.
- Explain the model: top features globally and for three individual customers.
- Save the model with a version name and serve it as an API with input validation.
- Write a batch job that scores every customer and writes a ranked CSV.
Python route and .NET route
- Python
- pandas, scikit-learn (Pipeline, ColumnTransformer, LogisticRegression, HistGradientBoostingClassifier), joblib, FastAPI. Start from quickpath.py lifecycle and serving.
- .NET (C#)
- ML.NET (LoadFromTextFile, OneHotEncoding, FastTree or LightGbm, BinaryClassification.Evaluate), Microsoft.Extensions.ML PredictionEnginePool in an ASP.NET Core minimal API.
Example input and output
- Input
{"tenure_months": 3, "monthly_charge": 95, "support_calls": 6, "plan": "monthly"}- Output
{"churn_probability": 0.93, "risk": "high", "model_version": "churn-v3"}
Data
Synthetic: generate it with a script so the rules that cause churn are known. Never use real customer data for practice.
Starter file structure
churn/
data/generate.py | Generate.cs
train.py | Train/Program.cs
serve.py | Api/Program.cs
batch_score.py | Batch/Program.cs
tests/
README.mdTests
- Model beats the baseline on recall at the chosen threshold
- API returns 400 for missing or non-numeric fields
- Same input gives the same score after a restart
- Batch output has one row per customer, sorted by risk
How it will be judged
- Metric choice justified by business cost
- No data leakage (no future information in features)
- Threshold explained in money or effort terms
- Explanations shown for individual customers
Security and privacy
Treat customer identifiers as personal data: keep them out of logs, protect the API with authentication, and never return other customers’ scores.
Definition of done
- Recall and precision reported on a frozen test set
- Model version returned with every prediction
- One-page note explaining the threshold and its trade-off
Stretch goals
- Add a fairness check across customer regions
- Add drift monitoring with PSI on tenure and charges
- Register each training run with data hash and metrics
What to show an employer
A short demo: show the baseline, the chosen model, the threshold decision and a live API call.
Completion
Saved in this browser only.