ML · Done
Which loan applicants are likely to default?
A baseline credit-risk classifier on the German Credit dataset, evaluated by what a missed bad payer costs, not by accuracy.
- Python
- pandas
- scikit-learn
- XGBoost
TL;DR
0.79
Best test ROC AUC (Random Forest). The three models land between 0.77 and 0.79.
48%
Recall on bad payers for Logistic Regression at the default 0.5 threshold: more than half are missed.
0.167
Starting decision threshold when one missed bad payer costs as much as five false alarms.
Context and questions
A lender wants to know, before approving a loan, whether the applicant is likely to pay it back. The two possible mistakes do not cost the same: approving someone who defaults is far more expensive than rejecting someone who would have paid.
- How much can simple models separate good payers from bad ones?
- Which variables carry the signal?
- Which metric and threshold make sense when the costs are asymmetric?
Data
The German Credit dataset (credit-g on OpenML): 1,000 applicants, about 70% good payers and 30% bad payers.
- No relevant missing values or duplicates.
credit_amountanddurationshow the strongest signal in the exploratory analysis.- Several numeric variables are strongly skewed.
Approach
Three notebooks: exploratory analysis, preprocessing and modeling.
- Preprocessing: log transform for skewed numeric variables, scaling, and ordinal or one-hot encoding for categorical ones, saved as a reusable pipeline.
- Models: Logistic Regression, Random Forest and XGBoost, compared with cross-validation and a held-out test set.
- Evaluation: recall on the bad-payer class, ROC AUC, precision and F1. Accuracy is not the target: a model that approves everyone is already 70% accurate.
Results
| Model | CV ROC AUC | Test ROC AUC | Recall | Precision | F1 |
|---|---|---|---|---|---|
| Logistic Regression | 0.794 | 0.769 | 0.480 | 0.610 | 0.537 |
| Random Forest | 0.785 | 0.789 | 0.387 | 0.630 | 0.479 |
| XGBoost | 0.769 | 0.777 | 0.440 | 0.550 | 0.489 |
Recall, precision and F1 are for the bad-payer class at the default 0.5 threshold.
Findings and recommendations
- The three models are close. This is a baseline, not an optimized system. More algorithms are unlikely to help much.
- Logistic Regression is the best operational baseline: the best recall and F1 on bad payers, and it is the easiest to explain.
- Random Forest ranks best (highest test ROC AUC), so it is a valid choice if applicants are sorted by risk instead of approved or rejected.
- The default threshold is the real problem. At 0.5 every model misses more than half of the bad payers. Lowering the threshold toward 0.167 is the first lever to pull.
Limitations and next step
- A small and old dataset: 1,000 rows. The numbers move with the train/test split.
- The 5-to-1 cost ratio is an assumption, not a figure from a lender.
- The metrics are reported at the default threshold; the cost-based threshold is not yet evaluated on the test set.
Next: tune the threshold against the cost assumption, handle the class imbalance explicitly, and try feature engineering before trying more models.