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 8 — Assignment Project: Predicting Diabetes Progression

Open in Colab

Overview

A hospital wants to know, one year in advance, which diabetes patients will get worse, so it can follow them more closely. You will build that prediction from start to finish, the way a data scientist would, and write a short report a doctor could read.

Data. The scikit-learn diabetes dataset: 442 patients, 10 measurements each (age, sex, body-mass index, blood pressure and six blood serum values, already standardised), and a number measuring disease progression one year later (25 to 346: higher is worse).

PartTaskPoints
AExplore the data and set up an honest evaluation15
BRegression: predict the progression score30
CClassification: flag the patients at high risk35
DA model card: report for the hospital20

Rules

  • Use random_state=42 wherever randomness appears, so your results can be reproduced.

  • The test set is used once, in the final cell of Parts B and C. Never to choose anything.

  • Cells marked checked have an automatic check under them; the other parts are graded with the rubric at the end.


Part A — Explore and Split (15 points)

A1 (checked). Split the data into 80% training and 20% test with random_state=42. Return X_train, X_test, y_train, y_test (features as DataFrames, targets as Series).

A2. Using the training set only, plot the distribution of the target and the correlation of each feature with it. Which three features look most useful? Write two or three sentences.

Your observations:


Part B — Regression (30 points)

B1 (checked). A model is only useful if it beats a trivial one. Complete baseline_mae : the mean absolute error, on the given validation data, of always predicting the training mean.

B2. Compare, with 5-fold cross-validation on the training set (scoring: mean absolute error), at least: the baseline (DummyRegressor), linear regression, ridge regression with λ\lambda (alpha) chosen by GridSearchCV, and a random forest. Show a table of the results.

B3. Fit your best model on the whole training set and report its MAE and R2R^2 on the test set (once). Explain in one sentence what the MAE means for a doctor.

Interpretation:


Part C — Flag the High-Risk Patients (35 points)

The hospital mostly needs a yes/no answer: will this patient be in the worst quarter?

C1 (checked). Complete make_labels: 1 when the target is above the 75th percentile of the training targets, else 0. (Use the training percentile for both sets: the test set must not influence the threshold.)

C2. Train at least two classifiers (for example logistic regression and a random forest) and compare their cross-validated precision, recall and F1 on the training set.

C3. Missing a high-risk patient is worse than an extra check-up: the hospital asks for a recall of at least 0.80. Using cross-validated probabilities on the training set, choose the decision threshold that reaches that recall with the best precision. Plot precision and recall against the threshold, then report the confusion matrix on the test set with your threshold.


Part D — A Model Card (20 points)

Write a short report (300–400 words) for the hospital, as a model card:

  1. Purpose: what the model predicts, and for whom.

  2. Data: where it comes from, how many patients, what it lacks.

  3. Performance: your test results in plain words (MAE; precision and recall at your threshold).

  4. Limitations and risks: what could go wrong (small dataset, one population, false alarms, missed patients), and what a doctor must not use it for.

  5. Recommendation: should the hospital use it, and how?

Your model card:


Grading Rubric

PartFull marks if…
A (15)correct split (checked); a clear exploration with sensible observations
B (30)baseline (checked); at least four models compared fairly by cross-validation; test set used once; a correct interpretation
C (35)labels from the training percentile (checked); two classifiers compared; a threshold chosen on training data that meets the recall target; test confusion matrix
D (20)all five sections, honest about limitations, understandable by a non-specialist