A credit scoring model for a microfinance lender issuing €500–€8,000 small business loans. Given 13 application-time features, the model flags likely defaulters for manual review.
Notebook: ML_final_project_B.ipynb
- Business-driven cost function. FP/FN costs (€100 review vs. €2,000 default loss) are derived from stated salary/loan/recovery-rate assumptions, combined with a staffing-based capacity constraint (max 40% of applicants reviewable per month) into a single expected-cost objective that every model is scored against.
- Optimized decision thresholds. Each model's threshold
t*is solved directly from its ROC curve to minimize expected cost under the 40% flag-rate cap, instead of using a default 0.5 cutoff. - EDA that shapes the modeling choices. An 18% default rate motivates stratified splitting and class weighting. Per-feature separation analysis surfaces
prior_defaults_countas the dominant signal (default rate climbs from 9% to 86% across its levels) and screens out weak features before any model is trained. - 11 models on one fair comparison. Logistic Regression, kNN, LDA, Naive Bayes, Decision Tree, Random Forest, XGBoost, two AdaBoost variants, and Bagging-kNN, each evaluated at its own cost-optimal threshold and ranked on a single table.
- A real error analysis. For the winning model: confidence of misclassifications, feature profiles of missed vs. caught defaults, cross-model agreement on hard cases, and recall by subgroup, used to tell apart genuinely undetectable risk from model weakness.
- Held-out test validation. The final model is retrained on the full training set and scored once on an untouched test set, with the threshold locked from validation.
Selected model: Advanced Logistic Regression (C=0.001, class_weight='balanced', t* = 0.511) — ranked #1 of 11 models on expected cost, recall, and ROC-AUC.
| Metric | Validation | Held-out Test |
|---|---|---|
| Expected cost / applicant | €64.34 | — |
| Recall (defaults caught) | 88.6% | 93.0% (53/57) |
| ROC-AUC | 0.874 | 0.902 |
| Flag rate | 39.4% | 39.0% (within 40% cap) |
A regularized linear model beat Random Forest and XGBoost here — with ~960 training rows and a largely monotonic risk relationship, the added complexity of the ensemble models wasn't rewarded. The error analysis shows the missed defaults cluster near t*, have average financial profiles, and go undetected by most of the other 10 models too, which points to risk that materialized after application (e.g. job loss) rather than a gap in the model.
| Section | Content |
|---|---|
| 0–0.1 | Setup, cost/capacity assumptions, cost-sensitive thresholding rule |
| 1 | EDA — class balance, distributions, outliers, target–feature separation |
| 2 | Stratified split, scaling (fit on train only) |
| 3 | Naive baseline (default 0.5 threshold) |
| 4 | 10 tuned models at cost-optimal thresholds |
| 5 | Model comparison, ranked by expected cost |
| 6 | Error analysis on the winning model |
| 7 | Conclusion, production retrain, held-out test results, limitations |
Open the notebook in Jupyter. Requires pandas, numpy, matplotlib, seaborn, scikit-learn, xgboost.