Project
Stage 1 project: Churn predictor from scratch
Everything from Stage 1 in one small program: load the churn data, clean it without leakage, train logistic regression with gradient descent in plain NumPy, pick a threshold, and compare against the baseline.
Time: ~2–3 hours if you build it yourself (recommended). Run the reference version:
PYTHONPATH=tools .venv/bin/python stage-1-foundations/project-churn-predictor/churn_predictor.py
Core (build this)
- Load
make_churn(), split 80/20 stratified, impute missing charges with the train median. - Standardize numeric features with train statistics; add the month-to-month flag.
- Train logistic regression with gradient descent (your Part 4 loop). Print the log loss every 500 steps — it must fall.
- Evaluate on the test set: accuracy at threshold 0.5, and the majority-class baseline next to it.
- Print the learned weights with their feature names, readable as risk factors.
Stretch
- Add L2 regularization (
loss + lambda * (w**2).sum()) and mini-batch updates; compare loss curves. - Write your own 5-fold cross-validation and report mean ± std accuracy.
Production level
- Package it as a module with functions (
load,preprocess,train,evaluate), a__main__entry point, and pytest tests for the preprocessing (no missing values out; means ≈ 0).
What "done" looks like
- A loss curve that falls and flattens.
- Test accuracy clearly above the 0.70 baseline.
- No statistic computed from test rows anywhere in the pipeline.
The reference implementation is churn_predictor.py; its output below came from a real run.
step log loss (train)
1 0.6931
500 0.4903
1000 0.4847
1500 0.4840
2000 0.4839
test accuracy at 0.5: 0.762 | baseline: 0.700
weights as risk factors:
tenure_months -0.67
monthly_charges +0.54
support_calls +0.47
month_to_month +1.75