Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 7 — Assignment Project: Auditing a Clinic’s Data

Open in Colab

Overview

A clinic wants a model that predicts, on the day a patient is discharged, whether they will be readmitted within 30 days. Before anyone trains a model, you are asked to audit the data: find what is wrong with it, fix what can be fixed, prepare it without leakage, and write down what a model trained on it can and cannot be trusted to do.

The dataset below is generated by code (so that everyone has the same data), and it has been built with nine problems of the kinds described in Chapter 7. Your job is to find them, with evidence.

PartTaskPoints
AThe audit: find the problems, with evidence30
BCleaning and a leak-free preparation pipeline30
CThe leakage hunt: measure what the leaks do to a score20
DA data card20

Part A — The Audit (30 points)

Use the tools of Chapter 7 (shape, dtypes, describe, value_counts, duplicated, isna, histograms, group comparisons) to find the nine problems. For each one, give:

  1. what the problem is,

  2. the evidence (a number, a table or a plot from your code),

  3. its kind (identifier, constant, duplicate, inconsistent category, unit mix, impossible value, missing-not-at-random, leak, repeated entity…).

Hint: one problem is about the unit of observation: what one row stands for, and whether rows are independent.

Your findings (a table of the nine problems):

#ProblemEvidenceKind
1

Part B — Cleaning and Preparation (30 points)

  1. Fix what can be fixed: remove the duplicates; merge the inconsistent labels; convert the weights that one ward recorded in pounds; mark impossible values as missing. Log every change and how many rows it touched.

  2. Drop the columns that must not be features, and say why for each.

  3. Build a scikit-learn ColumnTransformer + Pipeline that imputes, encodes and scales each kind of column correctly, with a missing-indicator where the missingness is informative. Explain each choice in one sentence.


Part C — The Leakage Hunt (20 points)

Train a random forest (300 trees, random_state=0) with your pipeline and report the cross-validated ROC AUC (Chapter 11; 0.5 is chance, 1.0 is perfect) in four settings, and explain each difference:

  1. with the leaky column added to the features, random 5-fold split;

  2. without it, random 5-fold split;

  3. without it, 5 folds by patient (GroupKFold);

  4. which of these numbers should the clinic believe, and why?

Your explanation:


Part D — A Data Card (20 points)

Write a one-page data card for the cleaned dataset, with these headings:

  • Source and unit of observation (what one row is; how many patients, how many rows)

  • Target (definition, class balance, the baseline accuracy)

  • Features (kind and preparation of each)

  • Known problems and fixes (from Part B, with counts)

  • Leakage risks (what must never be a feature; how the data must be split)

  • Limits (who is under-represented; what the model cannot be used for)

Grading Rubric

CriterionExcellentAdequateInsufficient
Audit (30)all 9 problems, each with clear evidence6–8 problems, or weak evidencefewer than 6
Cleaning (30)every fix logged with counts; correct pipeline; each choice justifiedpipeline works but choices unexplainedleaks in the preparation
Leakage hunt (20)the three scores, correctly explained, the right one chosenscores without explanationsettings missing
Data card (20)complete, precise, honest about limitsincompletemissing