Module 6 — Explainable & Responsible AI
Same theory-first structure as Modules 1–5: for every technique below, what it is, why it exists — the specific problem it was invented to solve — what else you could use instead, and a real financial example. Every module so far has answered "does it work?" and "can it be attacked?" Module 6 answers the question RR Finance has deferred since Module 1: "can we explain why it made this decision, and is that decision fair?"
Recap — what RR Finance already has
Module 6 is not a fresh start. Here's exactly what it inherits before turning the lens back on all of it.
A validated logistic-regression baseline (test ROC-AUC ≈ 0.69) — and the age column, deliberately excluded from every model's features, flagged "for Module 6" since Lesson 1.
A deeper ANN classifier, benchmarked against the Module 1 baseline — and adversarial attacks showing even a "working" model can be manipulated.
Text understanding, an aligned language model built from scratch, and RAG-powered tool-using agents — including a rule-based routing decision this module explicitly returns to.
Why explainability, why now
A model that cannot explain itself is not deployable in lending, no matter how accurate it is.
The legal reality
Under fair-lending frameworks like the US Equal Credit Opportunity Act, a rejected applicant is entitled to the specific reasons for that rejection — "the model said no" is not a compliant answer.
The technical gap
Module 1's logistic regression and Module 2's ANN both predict well enough to be useful and both remain, by default, black boxes about why any single prediction came out the way it did.
The deferred debt
age has sat in the dataframe since Module 1, excluded from every model's inputs but never actually audited for disparate impact — until this module.
The Adverse-Action Problem
Why a rejected applicant is owed more than a score.
An adverse-action notice is what fair-lending law requires a lender to give a rejected applicant: the specific, principal reasons their application was declined — not a probability, not "the algorithm decided."
✓ Why this frames the whole module
- Every technique in Modules 6 — SHAP, LIME, counterfactuals, fairness audits — exists to make this one legal requirement achievable for a model too complex to read directly
✗ What does NOT satisfy this requirement
- "The model's accuracy is 69%" — a global metric, not a reason for THIS applicant's specific decision
SHAP (Shapley Additive Explanations)
Borrowing a 1953 game-theory idea to split credit fairly among features.
SHAP assigns each feature a numeric contribution to one specific prediction, such that all contributions sum exactly to the gap between that prediction and the model's average output. It is the most theoretically grounded of the explanation methods in this module.
✓ Use it when
- You need explanations with a mathematical consistency guarantee — contributions that provably sum to the actual prediction, not just a plausible-looking ranking
- You want BOTH a global view (which features matter overall) and a local view (why THIS prediction) from one framework
✗ Watch out for
- Exact Shapley values are combinatorially expensive (every possible feature subset); real implementations use approximations —
KernelExplainer(model-agnostic, slower) or model-specific fast explainers (linear, tree)
debt_to_income and +0.19 to previous_defaults — real, individually attributable reasons, not a single opaque score.LIME (Local Interpretable Model-agnostic Explanations)
A second, independent way to ask the same local question.
LIME explains one prediction by perturbing the input locally, seeing how the model's output changes, and fitting a simple, interpretable model (weighted linear regression) to approximate the black box just in that local neighbourhood.
✓ Use it when
- You want a fast, intuitive, model-agnostic local explanation and don't need SHAP's summation guarantee
- As an independent cross-check against SHAP — genuine agreement between two differently-derived methods is stronger evidence than either alone
✗ Watch out for
- LIME's local linear surrogate is an approximation with no guarantee its coefficients sum to anything in particular; results can shift between runs unless the perturbation sampling is seeded
debt_to_income, previous_defaults, and credit_score at the top too — genuine agreement between two different mathematical approaches, not manufactured.num_features).Explaining a Neural Network
The same SHAP framework, a genuinely different function underneath.
Module 2's ANN is a non-linear, multi-layer function — nothing like the logistic regression's single linear decision boundary. SHAP's model-agnostic KernelExplainer treats it exactly the same way, wrapping it as a black-box predict_proba function and applying the identical Shapley-value machinery from Concept 2.
KernelExplainer is the general-purpose SHAP estimator that works on any model — the trade-off is speed: it treats the model as a black box and must query it many times per explanation, unlike faster model-specific explainers (linear, tree, or deep-network-specific).
✓ What the notebook demonstrates
- The exact same applicant, explained by both models — a direct, honest comparison of what each model actually leans on
✗ An honest finding, not smoothed over
- The reproduced ANN's test AUC trails the logistic regression's; its SHAP explanation for the same applicant partially diverges too — a weaker model isn't "the same reasoning, less accurate," it can genuinely attend to different signal
predict_proba repeatedly on perturbed/masked inputs to estimate each feature's marginal contribution, since it has no access to the ANN's internal gradients the way a deep-learning-specific explainer would.Counterfactual Explanations
"What would need to change?" — the recourse question SHAP and LIME don't answer.
SHAP and LIME explain why a prediction came out the way it did. A counterfactual explanation answers a different, more actionable question: what is the smallest realistic change to this applicant's inputs that would have flipped the decision?
✓ Use it when
- The deliverable is recourse — telling a rejected applicant what would change the outcome — not just a ranked list of important features
✗ An honest limitation, demonstrated directly
- For a genuinely high-risk applicant, the notebook's search finds NO single-feature change within a realistic range that flips the decision — only a combined two-feature change does. Some applicants simply don't have easy, single-lever recourse, and pretending otherwise would be dishonest
Interpretable-by-Design vs. Post-Hoc Explanation
The connecting thread back to Module 5's agent.
Module 5's loan-qualification agent routes between "calculate" and "reject" using an explicit, two-line boolean rule over retrieved policy text. Module 1's classifier decides "approve" or "reject" using millions of internal weight interactions no human can read directly. Both answer "why," but they need fundamentally different explanation strategies.
✓ What the notebook demonstrates
- The SAME counterfactual question — "what would need to change?" — asked of both systems: for the agent, the answer is read directly off the rule (two lines of Python); for the classifier, it takes SHAP, LIME, and a grid search across the decision boundary to get the same category of answer
✗ The nuance worth remembering
- Module 5's router is transparent because THIS implementation chose plain rules for inspectability — a production agent that used an LLM to make the same routing decision would become just as opaque as the classifier, and would need the exact same post-hoc toolkit
Group Fairness & the Age Audit
Finally paying off Module 1's single most-repeated forward reference.
Excluding age from a model's input features prevents DIRECT age discrimination but says nothing about whether the model's outcomes still differ systematically by age group — because other, included features (like employment_years or account_age_months) can act as a correlated proxy. Group fairness metrics measure the actual outcome gap directly.
fairlearn.
✓ What the notebook demonstrates
- Real, measured demographic-parity and equalized-odds gaps by age group, for BOTH the logistic regression and the ANN — computed with
fairlearn.metrics.MetricFrame, not assumed
✗ An honest limitation, stated plainly
- 800 rows split three ways by age leaves roughly 40–65 test applicants per group — these numbers are directional, not statistically conclusive, exactly the caveat Module 1 attached to its own metrics
Model Governance & Model Cards
Turning scattered findings into one artifact a governance function can actually use.
A model card (or governance report) is a structured, versioned record of what a model is, how it was tested, what its known limitations are, and what its fairness/explainability findings show — built for reviewers, auditors, and future maintainers, not just the data scientist who trained it.
✓ What the notebook demonstrates
- A governance report generated PROGRAMMATICALLY from the notebook's own real, computed numbers — never hand-typed, so it can never silently drift out of sync with what was actually found
✗ What this is NOT
- A marketing document. A real governance report says "here is what we don't know yet" as plainly as "here is what works" — the notebook's report explicitly lists its own sample-size and reproduction-fidelity limitations
Adverse-Action Notices in Practice (Lab)
The direct business deliverable of everything in this module.
The notebook's final lesson assembles SHAP's top reasons (Concept 2) and the counterfactual recourse path (Concept 5) into one templated document: a real adverse-action notice, in the plain language a rejected applicant is legally entitled to receive.
✓ What the notebook demonstrates
- A working
generate_adverse_action_notice()function that reuses Concept 2 and 5's actual computed values — no new modelling, pure integration of what the module already built
✗ What to try yourself
- Swap in a different applicant index from the test set and re-run — a genuinely different, applicant-specific notice comes out, because the underlying SHAP and counterfactual computation is real, not templated text
Module 6 hand-off
The notebook explains both the logistic-regression baseline and the reproduced ANN with SHAP and LIME, searches for real counterfactual recourse, finally delivers Module 1's deferred age-fairness audit with fairlearn, connects the classifier's post-hoc explanation needs to Module 5's inherently-interpretable agent routing rule, and closes by generating a real, working adverse-action notice — with a governance report and metrics summary saved as artifacts for the next module.