Exercises
Every exercise belongs to a lesson and comes with a Python notebook you can run in Google Colab without installing anything, plus a worked solution. Data is always synthetic or openly licensed and de-identified; datasets that need credentialed access are linked with instructions, never copied.
Foundations
- Healthcare data types: records, images, signals, notes and omics
Generate synthetic patient records with Synthea (or use its sample data), load them with pandas, and build a one-row-per-patient table with explicit choices about time windows and missing values.
Beginner · Clinical · Foundations · Data: Synthea synthetic patient records (CSV export)
- Data standards: FHIR, HL7, ICD, SNOMED CT, LOINC and OMOP
Read synthetic FHIR R4 patient bundles from Synthea, extract HbA1c and glucose Observations by LOINC code, and harmonise their units into one analysis table.
Beginner · Technical · Foundations · Data: Synthea synthetic FHIR R4 bundles
- Privacy and de-identification: HIPAA, GDPR and India's DPDP Act
Measure and reduce re-identification risk in a synthetic patient table, and see what each step costs in analytical detail.
Beginner · Clinical · Foundations · Data: Synthetic patients generated in the notebook (no real patient data)
- Setting up Python and Colab for clinical data work
Set up a working Python environment, then load, check, summarise and plot a small synthetic clinical table, handling missing values explicitly.
Beginner · Technical · Foundations · Data: Synthetic table written into the notebook (no real patient data)
- Diagnostic accuracy metrics: sensitivity, specificity, PPV, ROC and calibration
Explore how threshold and prevalence change the metrics of a simulated risk model, and check its calibration.
Beginner · Clinical · Foundations · Data: Synthetic patients generated in the notebook (no real patient data)
Machine learning
- Prediction or causation? Framing the clinical question
Explore confounding by indication in a simulated cohort, and see when adjustment does and does not recover the true treatment effect.
Beginner · Clinical · Machine learning · Data: Synthetic patients generated in the notebook (no real patient data)
- Building a cohort and avoiding data leakage
Build a 30-day readmission cohort from Synthea data with an explicit time zero, then measure how much each kind of leakage inflates performance.
Intermediate · Technical · Machine learning · Data: Synthea synthetic encounters and observations (CSV export)
- A logistic-regression risk score
Develop, evaluate and simplify a logistic-regression risk model on synthetic data, and test how it holds up when the population changes.
Intermediate · Technical · Machine learning · Data: Synthetic adults generated in the notebook (no real patient data)
- Gradient-boosted trees for readmission risk
Compare gradient boosting with logistic regression for 30-day readmission, fairly and on several metrics.
Intermediate · Technical · Machine learning · Data: Synthetic discharges generated in the notebook (no real patient data)
- Survival analysis: time-to-event models
Analyse a synthetic kidney-failure cohort with survival methods, and see how censoring and competing risks change the answer.
Intermediate · Technical · Machine learning · Data: Synthetic cohort generated in the notebook (no real patient data)
- Missing data and class imbalance
Handle informative missingness and a rare outcome properly, and measure the consequences of common shortcuts.
Intermediate · Technical · Machine learning · Data: Synthetic patients generated in the notebook (no real patient data)
- Explaining models with SHAP
Use SHAP to explain a readmission model, find its interaction, and test how explanations change with correlated inputs.
Intermediate · Technical · Machine learning · Data: Synthetic discharges generated in the notebook (no real patient data)
- Calibration and decision-curve analysis
Detect miscalibration at a new site, recalibrate, and judge clinical usefulness with a decision curve.
Intermediate · Clinical · Machine learning · Data: Synthetic sites generated in the notebook (no real patient data)
- Unsupervised learning for patient phenotypes
Cluster synthetic diabetes profiles, test whether the clusters are real and stable, and compare them with continuous variables for predicting an outcome.
Intermediate · Technical · Machine learning · Data: Synthetic profiles generated in the notebook (no real patient data)
Generative AI & LLMs
- How large language models work
Explore how next-token sampling and temperature create variability and plausible errors, using toy models that run without any API.
Beginner · Clinical · Generative AI & LLMs · Data: Synthetic sentences written in the notebook (no real patient data)
- Prompting for clinical tasks
Design, validate and evaluate a prompt that extracts diabetes information from synthetic clinic notes.
Intermediate · Technical · Generative AI & LLMs · Data: Twenty synthetic clinic notes with clinician-style labels, written for the notebook
- Medical LLMs and their benchmarks
Analyse benchmark results like a reviewer: quantify uncertainty, compare models properly and look for warning signs.
Intermediate · Clinical · Generative AI & LLMs · Data: Simulated benchmark answers generated in the notebook
- Hallucination and grounding
Measure and reduce hallucinations and omissions in synthetic AI-generated clinic notes.
Intermediate · Clinical · Generative AI & LLMs · Data: Ten synthetic consultation transcripts with AI-style draft notes, written for the notebook
- Fine-tuning with LoRA on synthetic data
Implement and explore LoRA in NumPy, then plan a responsible clinical fine-tuning project.
Advanced · Technical · Generative AI & LLMs · Data: Synthetic matrices and examples generated in the notebook
- Multimodal models: text, images and more
Explore zero-shot classification and shortcut learning with toy embeddings, then with an open chest X-ray dataset if available.
Intermediate · Technical · Generative AI & LLMs · Data: Toy embeddings generated in the notebook; optional extension uses an openly licensed chest X-ray dataset
- Summarisation and ambient clinical documentation
Audit synthetic AI-drafted notes against their final versions and design a monitoring report.
Beginner · Clinical · Generative AI & LLMs · Data: Twenty synthetic draft and final note pairs, written for the notebook
Educational content only. This material teaches methods; it is not clinical advice. Code, models and examples here are not validated medical devices and must not be used to make decisions about real patients without proper clinical validation, governance and any required regulatory approval. Examples use synthetic or openly licensed de-identified data only. Never paste identifiable patient information into public AI tools. Mentions of models, tools or vendors are for identification, not endorsement.