CSC3119 Β· Module 9 of 9

Capstone: Regional Referral Hospital Stroke Risk Pipeline & Explainable AI (XAI)

Deploy the Ministry of Health stroke predictor with threshold calibration and SHAP feature attributions

~56 min to study properly

We unite all eight preceding modules into our comprehensive capstone: deploying the Cerebrovascular Accident Risk Predictor for a high-volume Regional Referral Hospital in Uganda.

Checkpoint Β· the examiner asks

Why must clinical classification thresholds be calibrated away from the default 0.5, and how does SHAP (Shapley Additive exPlanations) establish clinical trust for attending doctors?

In one minute

The capstone ties everything together for the Regional Referral Hospital: with ~5% prevalence the default 0.5 threshold misses most strokes, so calibrate it (e.g. 0.22) to maximise recall within triage capacity. Physicians need explanations, not bare probabilities: SHAP gives each feature's additive contribution from the base rate to this patient's risk, turning a score into clinical action.

Traps examiners look for
  • Keeping the 0.5 threshold on a 5%-positive problem.
  • Presenting a risk score with no explanation to a physician.
  • Reading SHAP values as causal effects rather than model attributions.
Read

Study notes

01The end-to-end system

The capstone joins every module into one service for a high-volume Ugandan Regional Referral Hospital:

  1. Data β€” the stroke dataset with leakage-free preprocessing in an sklearn Pipeline (module 1).
  2. Artifact β€” the whole pipeline saved with joblib, versioned and checksummed (module 2).
  3. API β€” FastAPI + Pydantic /predict, model loaded once per worker (module 3).
  4. Infrastructure β€” CPU instances in a nearby region, Spot only for retraining (module 4).
  5. Container β€” multi-stage, non-root Docker image (module 5).
  6. Release β€” canary with automatic rollback (module 6).
  7. Performance β€” ONNX/INT8 if latency demands it (module 7).
  8. Monitoring β€” PSI drift detection and delayed-label evaluation (module 8).

What the capstone adds: choosing the decision threshold for clinical use, and explaining each prediction to the physician.

02The threshold is a clinical decision

A classifier outputs a probability; a threshold turns it into an action (refer to the chronic-care clinic or not). The default 0.5 is arbitrary β€” and terrible when only ~5% of patients have strokes, because most stroke patients get probabilities well below 0.5.

Lowering the threshold trades precision for recall:

ThresholdRecallStrokes missed / 1,000 patientsReferrals / month
0.50~65%~18~64
0.22~88%~6~187
0.15~92%~4~264

The right threshold balances the cost of a missed stroke against the clinic's capacity to see referred patients. Choose it on a validation set (never the test set), document why, and revisit it when prevalence or capacity changes. Per the Ministry of Health integration guidelines (June 2025), high-risk patients at triage are enrolled in the chronic care clinic β€” so the threshold directly sets the clinic's workload.

03Why black boxes are not acceptable

"This patient's stroke risk is 42%" is not enough for a referral physician. They need to know why β€” to check the model against their own judgement, catch data errors (an age typed as 670), explain the decision to the patient, and decide what to treat.

Explainability also supports accountability and fairness: you can audit whether the model leans on features it shouldn't, and justify decisions to patients and regulators. In clinical settings an unexplained score is often simply ignored.

04SHAP β€” local, additive explanations

SHAP (SHapley Additive exPlanations) assigns each feature a contribution to this prediction, based on Shapley values from cooperative game theory. The contributions are additive:

prediction = base value + Ξ£ feature contributions

where the base value is the model's average output (β‰ˆ the hospital's base rate). For a patient: "base risk 5% β†’ this patient 42%: +18 points from age 68, +12 from hypertension, +7 from glucose 220 mg/dL…".

Key properties for exams:

  • Local β€” explains one prediction; averaging |SHAP| across patients gives global importance.
  • Additive and consistent β€” contributions sum exactly to the prediction (in the model's output space, e.g. log-odds for logistic/XGBoost models).
  • TreeSHAP computes exact values efficiently for tree models like XGBoost.
  • SHAP explains the model, not causality: "+12 from hypertension" means the model's prediction rose, not that hypertension causes 12 points of risk for this person.
Watch it done

Worked examples

Worked example 1

Choosing a threshold under capacity

The clinic can take at most 200 new referrals a month from ~1,000 screened patients (5% prevalence). Using the table, which threshold would you pick and what do you trade off?

    Worked example 2

    Reading a SHAP explanation

    Base value (log-odds) = βˆ’2.95 (β‰ˆ5%). A patient's contributions: age +0.94, glucose +1.54, BMI +0.32, hypertension +0.85, heart disease +0.65. What is the predicted probability, and which feature matters most?

      Vocabulary

      Key terms

      Uganda MOH 2025 Integrated Non-Communicable Disease Guidelines

      In Sub-Saharan Africa, cerebrovascular accidents occur at younger median ages (often under 55) due to undiagnosed hypertension. Integrating predictive MLOps pipelines with explainable SHAP dashboards in regional referral hospitals allows early preventative intervention before catastrophic acute events.

      Practise

      Quick check

      0 of 8 correct so far. Wrong answers come with an explanation β€” and the buddy can unpack them.

      Q1A hospital model outputs stroke probability = 0.28. If the threshold is 0.5, the patient is flagged negative; if threshold is 0.20, flagged positive. Why choose 0.20?

      Q2What property guarantees that the sum of all SHAP values plus the baseline expected value equals the model's exact prediction for a patient?

      Q3Why is the 0.5 threshold a poor default for the stroke model?

      Q4Lowering the threshold usually…

      Q5Where should the decision threshold be chosen?

      Q6SHAP values for one patient sum to…

      Q7'+12 points from hypertension' in a SHAP plot means…

      Q8How do you get global feature importance from SHAP?

      Exam-style

      Written practice

      Short answer6 marks

      Why is the default 0.5 threshold wrong for the stroke model, and how would you choose a better one?

      Short answer5 marks

      What does a SHAP value represent, and how would a physician use a SHAP explanation for one patient?

      Long answer15 marks

      You are presenting the stroke-risk system to the hospital's clinical governance board. Describe the full system end to end and justify the design decisions that make it safe, explainable and maintainable β€” data handling, metric and threshold choice, serving architecture, release process, explanations and monitoring.

      Watch

      Videos

      Fresh picks are chosen by AI every day.
      Hands-on

      Clinical Stroke Risk, Threshold Calibration & SHAP Feature Attribution Simulator

      4 guided tasks: predict, experiment, explain β€” then challenge yourself. Plus 2 coding exercises you run right in the browser.

      Start the lab