KatInterview

Build and Compare Credit Risk Models: Logistic vs Tree Ensemble

Machine LearningModel answer
MediumModel answerMachine Learningclassificationimbalanced-datamodel-calibration

Last updated

Develop both a linear baseline and a tree-based classifier for predicting loan defaults, covering feature engineering, validation, calibration, and deployment.

Context

You're developing a binary classifier to identify accounts likely to stop payment within 90 days (default = 1 vs current = 0). Your training set has 500,000 records with roughly 2% positive examples—a significant class imbalance.

Available signals:

  • Numeric fields: income-to-debt ratio, credit line usage percentage, account holder age, minimum payment coverage (contains nulls, heavy tails, some extreme values)
  • Categorical with many levels: transaction category codes, geographic region
  • Ordered categories: risk grade from A (lowest risk) to G (highest risk)

Your Assignment

Part 1: Feature Preparation and Pipeline Design

Outline the transformations required for a linear model versus a tree-based ensemble. Show how to organize these steps in a scikit-learn pipeline so that fitting, imputation, and encoding happen only on training data during cross-validation.

Part 2: Capturing Complex Patterns

  • Explain what a linear model requires to represent curved relationships and variable combinations (such as polynomial expansions, binning, or interaction features).
  • Describe how ensemble methods built from decision trees naturally discover these patterns without manual feature construction.

Part 3: Evaluation Setup and Imbalance Handling

  • Propose a cross-validation scheme appropriate for time-ordered financial records and heavily skewed classes.
  • Compare techniques for addressing imbalance (e.g., class weighting, undersampling, synthetic oversampling) and their effect on probability estimates.

Part 4: Probability Calibration and Decision Boundaries

  • Explain why tree ensemble scores often cluster away from 0 and 1, while linear models trained with log-loss tend to be well-calibrated.
  • Given a business scenario where missing a default costs $5,000 in unrecovered funds and incorrectly blocking a good account costs $150 in lost revenue, derive the classification threshold that minimizes expected cost (instead of using 0.5).

Part 5: Deployment and Compliance

Compare the two modeling approaches across these operational concerns:

  • Response time requirements (99th percentile under 15 milliseconds)
  • Explainability obligations under consumer credit regulations
  • Model refresh frequency and monitoring for distribution shift

Hints

Hint 1

Fit all transformers inside a pipeline to avoid leaking information from validation folds into training.

Hint 2

Tree ensembles learn interactions automatically through sequential splits; linear models need explicit feature crosses.

Hint 3

Use time-based splits with a gap to prevent label leakage; handle imbalance through reweighting or threshold tuning rather than synthetic data.