Skip to content

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

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.