AI & ML Quick Path

Capstone 1 of 8

Customer churn prediction service

Machine learningIntermediateEffort 20–30 h (estimate)

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

  1. Synthetic customer table (CSV)
  2. Feature pipeline (tenure, charges, support calls, plan)
  3. Baseline and two candidate models
  4. Evaluation on a frozen test set (recall, precision, AUC)
  5. Saved model with version
  6. Prediction API (/health, /predict) and nightly batch scoring

Build steps

  1. Generate 5,000 synthetic customers with a churn rate near 20% and save them as CSV.
  2. Explore the data: churn rate by plan, tenure and number of support calls.
  3. Build the majority-class baseline and record its accuracy (it will look high; explain why it is useless).
  4. Train logistic regression and gradient boosting; compare on the same test set using recall and AUC.
  5. Choose a decision threshold from the cost of a missed churner versus an unnecessary call.
  6. Explain the model: top features globally and for three individual customers.
  7. Save the model with a version name and serve it as an API with input validation.
  8. 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

Structure (Python file | .NET project)
churn/
  data/generate.py | Generate.cs
  train.py | Train/Program.cs
  serve.py | Api/Program.cs
  batch_score.py | Batch/Program.cs
  tests/
  README.md

Tests

  • 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.