Capstone: Regional Referral Hospital Stroke Risk Pipeline & Explainable AI (XAI)
CSC3119 Ā· Lab

Clinical Stroke Risk, Threshold Calibration & SHAP Feature Attribution Simulator

Run the triage model on one patient and read the SHAP explanation a physician would see — then move the decision threshold for the whole hospital and trade missed strokes against clinic capacity.

  1. 1 Ā· Predict0/1
  2. 2 Ā· Experiment0/2
  3. 3 Ā· Explain0/1
  4. 4 Ā· Code it0/2
  5. 5 Ā· Challenge
  6. 0/4 tasks done

Predict first

Commit to a guess before you touch anything. Being wrong here is how it sticks.

Lowering the threshold raises recall from 65% to 88% in a cohort with 200 true strokes. How many more patients get preventive care?

Experiment

Move the controls and watch the outputs. Goals tick off automatically when you reach them.

One patient, explained

Predicted stroke risk
79.3%
base rate 5.0% → log-odds āˆ’2.95 + Ī£ SHAP = 1.34
SHAP contributions (log-odds; + raises risk)
Glucose +1.54↑
Age +0.94↑
Hypertension +0.85↑
Heart disease +0.65↑
BMI +0.32↑

Decision threshold for the hospital

1,000 patients a month, 5% prevalence. Patients above the threshold are booked into the chronic-care clinic.

Recall
64%
Strokes missed / month
18
Clinic referrals / month
64
Precision
50%

Lowering the threshold catches more strokes but books more healthy patients into the clinic. The right threshold is a clinical-capacity decision, not 0.5 by default.

Explain it

Put what you saw into words. This is what the exam will ask you to do.

Why is the default 0.5 threshold wrong here, and how do SHAP values make a prediction actionable for a physician?

Code it

Write real code against real data. Python and SQL run right here in your browser and hidden tests check your work; the AI reviews it like an examiner.

Pythonexam

Choose the threshold the clinic can handle

scores are validation-set predicted probabilities and y the true outcomes (1 = stroke). The chronic-care clinic can take at most capacity referrals per 1,000 patients.

Write choose_threshold(y, scores, capacity) returning the lowest threshold from np.round(np.arange(0.05, 0.96, 0.01), 2) whose referral rate (share of scores ≄ threshold) Ɨ 1,000 is ≤ capacity — that maximises recall within capacity. Also write recall_at(y, scores, t).

Ctrl/⌘ + Enter to run

Challenge

Fixed variations, a new problem every day, and unlimited AI challenges built from your current settings.

Decision Threshold Calibration for Clinical Recall

At the default 0.50 probability threshold, the classifier flags 30 out of 50 stroke cases (60% recall). Calibrating the decision threshold down to 0.22 enables the model to detect 46 out of 50 stroke cases. What is the new clinical Recall in percent?