Imbalanced Churn Classifier in Raw NumPy
Build logistic regression in raw NumPy on a real imbalanced binary dataset, engineer features without leakage, compute every metric yourself, tune the decision threshold and check against scikit-learn.
Lessons this project uses
- 1Linear RegressionPhase 2: Machine learning fundamentals
- 2Logistic RegressionPhase 2: Machine learning fundamentals
- 3Feature Engineering & SelectionPhase 2: Machine learning fundamentals
- 4Model EvaluationPhase 2: Machine learning fundamentals
- 5Handling Imbalanced DataPhase 2: Machine learning fundamentals
What You'll Build
A churn style classifier for a real business problem where the positive class is rare. You write logistic regression with gradient descent, L2 regularization and class weights in NumPy, prepare mixed numeric and categorical features without leaking test data, and evaluate it with metrics that do not lie on imbalanced data. Then you pick a decision threshold on validation data and report test results exactly once.
Requirements
- Dataset. Choose a public tabular binary classification dataset where the positive class is between 3% and 35% of rows, with at least 2,000 rows and at least one categorical column (for example a telecom churn, bank marketing or credit default dataset). State the source, the positive rate and why a false negative or false positive matters in that setting.
- Splits. Stratified train/validation/test split with a fixed seed. The test set is used once, at the end.
- Features. Implement standardization, one-hot encoding and missing value imputation yourself. Fit all statistics on the training split only and apply them to validation and test. Add at least one engineered feature (a ratio, log transform, bin or interaction) and say why.
- Model. Logistic regression in NumPy: stable sigmoid, binary cross-entropy, L2 penalty, class weights, batch gradient descent. Save the training loss curve to
results/loss_curve.png. - Metrics from your own code. Confusion matrix, precision, recall, F1, ROC-AUC and PR-AUC (average precision). Include a majority class baseline so the accuracy trap is visible.
- Reference check. Train
sklearn.linear_model.LogisticRegressionon the same features and report its ROC-AUC next to yours. Also cross-check your metric functions againstsklearn.metricson the same predictions (differences under 1e-6). - Imbalance strategies. Compare at least three on validation PR-AUC and F1: no weighting, class weights, and one resampling method (random oversampling or SMOTE).
- Threshold tuning. Sweep thresholds on validation predictions, pick the one that maximizes F1 (or a cost you define), save
results/threshold_curve.png, then apply it to the test set once. - Save all numbers to
results/metrics.json; one command reruns everything.
Constraints
- NumPy, pandas and matplotlib for the model and features; scikit-learn only for the step 6 comparison checks.
- CPU only, laptop scale. If your dataset is large, subsample to at most 50,000 rows with a fixed seed.
- Free public data only; include the download step or instructions, do not commit large data files.
Stretch Goals
- Implement stratified 5-fold cross-validation and report mean and std of PR-AUC.
- Add Matthews correlation coefficient and a calibration plot.
- Compare L1 vs L2 regularization and list which features go to zero.
How to Submit
Public GitHub repo with README.md, src/ (features, model, metrics) or a main.py, requirements.txt, a data download script or clear instructions, and results/ with metrics.json, loss_curve.png and threshold_curve.png. The README must explain how to run it, show a table of your results (baseline, each imbalance strategy, final test), justify your chosen threshold in business terms, list the limitations of your model, and describe one thing that did not work.
How It's Reviewed
Professor Katalock reads your repository and the evidence you paste, and scores each criterion out of 100. You pass with a weighted total of 70 or more and no criterion below 40. A copied or padded submission is flagged and fails.
Submit
Push your work to a public GitHub repository with a README that explains how to run it, then paste the evidence below. Up to 3 reviews a day, free.
- Link to the public GitHub repo
- Full terminal output of the main run command
- Contents of results/metrics.json
- The loss_curve.png and threshold_curve.png plots
- Printed comparison of your metric functions against sklearn.metrics on the same predictions
Reviews are done by AI against the rubric above. They check the evidence in your repository; they are not a substitute for a human code review, and a review can be wrong. If you think it is, improve the README so the evidence is unmistakable and resubmit.