Test 14 - Model Explainability
Purpose
Generate explainer-based reports and group-level feature summaries for the top predicted test samples. Produces group->feature mappings and a compact group statistics table.
Required Inputs
WORK_DIR: working directory withcompare/3.test_cohort.predsand model artifactsMODEL_PATHandEXPLAINABLE_MODEL_PATH(model with explainability hooks; expected under${WORK_DIR}/model/)TOP_EXPLAIN_PERCENTAGE: integer percent (used to select top scoring samples)TOP_EXPLAIN_GROUP_COUNT: integer number of top groups to include in final stats
How to Run
What This Test Does
- Selects the top
TOP_EXPLAIN_PERCENTAGEpercent highest-scoring unique patients from${WORK_DIR}/compare/3.test_cohort.predsto build explainer examples. - Runs
CreateExplainReportagainst the explainer model (EXPLAINABLE_MODEL_PATH) and the selected samples to create${WORK_DIR}/ButWhy/explainer_examples/test_report.tsv. - Reformat and aggregate the explainability output to:
- Map groups to features and features to signal categories
- Produce group histograms and a final
group_stats_final.tsvcontaining Group, Frequency, Percentage and leading features
Output Location
${WORK_DIR}/ButWhy/explainer_examples/test_report.tsv${WORK_DIR}/ButWhy/explainer_examples/group_stats_final.tsv- temporary files under
${WORK_DIR}/tmp/used during reformatting
How to Interpret Results
test_report.tsvcontains detailed per-sample explainer output. Use it to inspect example explanations.group_stats_final.tsvsummarizes how many examples belong to each explanation group and lists top features per group — useful to prioritize group-level analyses.
Troubleshooting
- If
CreateExplainReportfails, run it manually with the selected sample file${WORK_DIR}/ButWhy/explainer_examples/top.samplesto inspect errors. - If expected groups/features are missing, check
TOP_EXPLAIN_PERCENTAGEandTOP_EXPLAIN_GROUP_COUNTvalues (they control sample selection and report granularity).
Files to inspect
${WORK_DIR}/ButWhy/explainer_examples/test_report.tsv${WORK_DIR}/ButWhy/explainer_examples/group_stats_final.tsv${WORK_DIR}/tmp/*intermediate mapping files