Part IV — Supervised Learning: Regression & Linear Classifiers · Chapter 11

Build a calibrated financial risk scoring engine

Hook

Everything in this part comes together for one job: score a loan applicant's risk across more than two categories, using probabilities a lender could actually act on. Get the regularization wrong, though, and the model doesn't just get less accurate — it stays just as confident while being wrong, which is a far more dangerous failure in a system making real lending decisions.

Intuition
Alexdebt=2, late=0 predicted low (true: low)
Baodebt=5, late=0 predicted medium (true: medium)
Coradebt=8, late=3 predicted high (true: high)
Dejadebt=3, late=2 predicted medium (true: medium)

4 of 4 applicants correctly classified at this λ

Four applicants, three risk classes, one softmax classifier. At λ=0 every prediction matches the true risk. Push λ up and watch predictions start flipping to the wrong class — while the probability bars stay just as confident-looking as before.

Formalize

The engine is multinomial logistic regression — softmax over a per-class linear score — with the same weight-shrinkage mechanism from the ridge chapter applied to every class's weights at once:

pk(x)=softmax(wk(λ)x+bk)k,wk(λ)=wkraw1+λp_k(\mathbf{x}) = \text{softmax}\big(\mathbf{w}_k^{(\lambda)} \cdot \mathbf{x} + b_k\big)_k, \qquad \mathbf{w}_k^{(\lambda)} = \frac{\mathbf{w}_k^{\text{raw}}}{1+\lambda}
  • wkraw\mathbf{w}_k^{\text{raw}} — class kk's unregularized weight vector, over the applicant's features.
  • bkb_k — class kk's bias — left unpenalized, exactly as in the ridge and lasso chapters.
  • λ\lambda — the shrinkage strength; this 1/(1+λ)1/(1+\lambda) form is ridge's own closed-form shrinkage in the special case of standardized, uncorrelated features.
  • pk(x)p_k(\mathbf{x}) — the calibrated probability applicant x\mathbf{x} belongs to risk class kk.
  1. Regularization here isn't about sparsity — it's about calibration

    Unlike lasso, nothing here is meant to zero out; the goal is to keep any one class's weights from dominating the score purely due to unconstrained magnitude.

  2. Softmax doesn't know the weights were regularized

    Softmax just normalizes whatever logits it's handed — it has no way to flag "these logits came from an over-shrunk model" versus "these logits are trustworthy." A miscalibrated model can look exactly as confident as a good one.

  3. Over-regularization has a real direction of failure here

    As every class's weights shrink toward zero, the classifier increasingly falls back on each class's bias alone — and the bias ranking (low > medium > high) means over-shrinking systematically under-estimates risk, not randomly misclassifies it.

Play
Alexdebt=2, late=0 predicted low (true: low)
Baodebt=5, late=0 predicted low (true: medium)
Coradebt=8, late=3 predicted medium (true: high)
Dejadebt=3, late=2 predicted low (true: medium)

accuracy: 1/4 — average confidence in the winning class: 78.1%

Watch accuracy and average confidence side by side as λ moves. Accuracy falls off a cliff between λ=0.2 and λ=0.3 — but average confidence barely moves, staying in the 70s-to-80s percent the entire time. Confidence alone would never warn you that the model just started getting people wrong.

Worked example

Bao: debt ratio 5, 0 late payments — a lender's judgment: medium risk.

  1. At λ=0.2, correctly medium — but barely

    Shrunk weights give logits (low, medium, high) = (1.833,2.000,0.167)(1.833, 2.000, 0.167). Exponentiate each:

    • e1.8336.252e^{1.833} \approx 6.252
    • e2.0007.389e^{2.000} \approx 7.389
    • e0.1671.182e^{0.167} \approx 1.182

    Dividing by the sum 6.252+7.389+1.18214.8236.252+7.389+1.182 \approx 14.823: p(0.422,0.498,0.080)p \approx (0.422, 0.498, 0.080) — medium wins, but by a margin of less than 0.08.

  2. At λ=0.3, that thin margin flips

    Logits become (2.154,2.000,0.154)(2.154, 2.000, -0.154) — low has overtaken medium. Exponentiate each:

    • e2.1548.621e^{2.154} \approx 8.621
    • e2.0007.389e^{2.000} \approx 7.389
    • e0.1540.857e^{-0.154} \approx 0.857

    Dividing by the sum 8.621+7.389+0.85716.8678.621+7.389+0.857 \approx 16.867: p(0.511,0.438,0.051)p \approx (0.511, 0.438, 0.051). Bao is now predicted low risk: an under-flagged applicant, purely from one notch more shrinkage.

  3. Confidence gives no warning either way

    Bao's top-class probability is 0.4980.498 right before the flip and 0.5110.511 right after — essentially unchanged. The model is equally "sure" of two opposite answers.

Checkpoint

Pick the λ that still classifies all 4 applicants correctly.

Pick a value to try it
Summary
pk(x)=softmax(wk(λ)x+bk)k,wk(λ)=wkraw1+λp_k(\mathbf{x}) = \text{softmax}\big(\mathbf{w}_k^{(\lambda)}\cdot\mathbf{x}+b_k\big)_k, \qquad \mathbf{w}_k^{(\lambda)} = \frac{\mathbf{w}_k^{\text{raw}}}{1+\lambda}

A calibrated multi-class scorer combines softmax's normalized probabilities with regularization's weight control — but calibration is not accuracy. This toy engine stays confidently wrong across a wide range of over-shrunk λ, which is exactly why choosing λ needs a real accuracy check, not a glance at how sure the model sounds.