KatalockAi AcademyBack to KatalockAi
Phase project, required for the Phase 2 certificate

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.

about 5 h Reviewed against a 5-point rubric
Submit your project Get coached by Professor Katalock

Lessons this project uses

  1. 1Linear RegressionPhase 2: Machine learning fundamentals
  2. 2Logistic RegressionPhase 2: Machine learning fundamentals
  3. 3Feature Engineering & SelectionPhase 2: Machine learning fundamentals
  4. 4Model EvaluationPhase 2: Machine learning fundamentals
  5. 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

  1. 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.
  2. Splits. Stratified train/validation/test split with a fixed seed. The test set is used once, at the end.
  3. 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.
  4. 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.
  5. 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.
  6. Reference check. Train sklearn.linear_model.LogisticRegression on the same features and report its ROC-AUC next to yours. Also cross-check your metric functions against sklearn.metrics on the same predictions (differences under 1e-6).
  7. Imbalance strategies. Compare at least three on validation PR-AUC and F1: no weighting, class weights, and one resampling method (random oversampling or SMOTE).
  8. 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.
  9. 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.

CriterionWeightHow it's checked
Model and metrics correctness25Logistic regression with stable sigmoid, BCE, L2 and class weights is implemented in NumPy; hand written metrics match sklearn.metrics within 1e-6 in pasted output; NumPy ROC-AUC is close to the sklearn LogisticRegression ROC-AUC.
Leakage-free features20Imputation, scaling and encoding statistics are fit on the training split only and reused for validation and test; the split is stratified with a fixed seed; at least one engineered feature is present and justified.
Imbalance handling and threshold20metrics.json compares no weighting, class weights and one resampling method on validation PR-AUC and F1, threshold_curve.png exists, and the threshold is chosen on validation before a single test evaluation.
Code quality15Code is split into feature, model and metric functions or modules, seeds are fixed, one command reproduces the results, and no large data files are committed.
README explanation and reflection20README names the dataset and positive rate, shows the learner's own results table including the majority baseline, explains the threshold choice in terms of the cost of errors, lists limitations, and describes something that did not work.

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.