Machine Learning·Capstone·20 min·0/3 exercises

Capstone: the model card

A dataset was deleted from scikit-learn. Write down what yours assumes.

data provenanceload_boston removalmodel cardsknown limitswho is affected

Watch it happen

Play it through, or step back and forth yourself.

from sklearn.datasets import load_boston

ImportError:
  `load_boston` has been removed from scikit-learn
  since version 1.2.
Removed, not deprecated — the maintainers decided it should stop being taught at all. It had been the canonical regression example since 1978.

load_boston used to sit alongside iris and digits. Try it in scikit-learn 1.2 or later and it is simply gone — removed, not deprecated. Understanding why is the most useful thing in this lesson.

The idea

load_boston used to sit alongside iris and digits — 506 houses, thirteen columns, the canonical regression teaching example since 1978. Try it in scikit-learn 1.2 or later:

from sklearn.datasets import load_boston

ImportError: `load_boston` has been removed from scikit-learn since version 1.2.

Removed, not deprecated. The maintainers decided it should stop being taught at all.

Why it went

One of its thirteen columns was engineered on an explicitly racist premise about neighbourhood composition and house prices. It sat in courses, textbooks and tutorials for decades, and almost nobody read the column list — because why would you? It was the standard example.

And it isn't the only one: fetch_lfw_people, the face dataset, carries very different demographic assumptions than most people assume; ImageNet's label set has been repeatedly criticised. This is not a rare failure.

The general lesson

It isn't "watch out for that one dataset". It's that a dataset carries the assumptions of whoever built it, and those assumptions are invisible in X.shape, in describe(), and in every cross-validation score you will ever compute.

Lesson 32 made a version of this point: the breast cancer model predicts one hospital's labels, on one population, with one set of imaging equipment in 1993 — and every fold of your cross-validation comes from those same 569 people, so nothing in your evaluation can warn you.

The only defence is to read what the columns mean, and to write down what you learn.

The model card

A model card is a short, honest document that ships with the model. Half a page. It's what makes a result reusable by somebody who wasn't in the room — including you, in six months.

Eight sections:

  1. What it predicts — the target in words, and the decision it serves.
  2. Training data — source, size, dates, who collected it, and what it excludes.
  3. Preprocessing — the pipeline, in enough detail to rebuild.
  4. Metric and why — chosen from costs, before modelling (lesson 5).
  5. Performance — the test score with a spread, and the baseline beside it (lessons 8, 24).
  6. Threshold — the operating point and the costs that set it (lesson 7).
  7. Known limits — where it should not be used.
  8. Who is affected — when it's wrong, and how badly.

A worked example

# Late-delivery warning model — v1

PREDICTS    probability a delivery exceeds 30 minutes
SERVES      whether to send an apology text in advance

DATA        900 deliveries, March 2026, one stall
            17% of prep_min missing, NOT at random —
            it goes missing when the stall is busiest
EXCLUDES    other cities, other seasons, festival days

PIPELINE    median impute (+ missingness indicator) → scale
            one-hot (handle_unknown="ignore")
            logistic regression, C=1, class_weight="balanced"

METRIC      ROC AUC to select; recall to operate
            a miss ≈ ₹200, a false alarm ≈ ₹5

TEST        AUC 0.8465        baseline accuracy 0.7778
THRESHOLD   0.10 → catches 50/50 late, 100 false alarms

LIMITS      - one stall, one month. Do not deploy elsewhere
              without re-measuring.
            - assumes the ₹5 alarm cost. At 150 texts per
              225 orders, people stop reading them and that
              assumption breaks.
            - riders are named features; a new rider gets
              all zeros and a worse prediction.
            - NOT a promise to the customer.

AFFECTED    a customer receives an unnecessary text.
            Low stakes — which is why this threshold is
            defensible and would not be in a clinic.

Notice how much of it is caveats, and that every number came from a specific lesson rather than from a feeling. The LIMITS block is the part that would have stopped Boston being taught for forty years — and it's the part that gets cut for length.

If you write nothing else, write that block.

The last question

Before you ship anything: who is affected when this is wrong?

  • Late chai → an unnecessary text. Nobody much.
  • A loan decision → a refused application. The applicant.
  • A missed malignancy → a delayed diagnosis. A person.

The fit call is identical in all three. The predict call is identical. Every technique in this track applies equally to all of them.

The responsibility is not identical, and nothing in the library will remind you of that. It has to come from you, and the model card is where it gets written down.

That's the track

Thirty-five lessons. The recurring finding is worth restating: on our data logistic regression beat every ensemble, PCA lost information, polynomials made it worse, and the single largest gain came from add_indicator=True — a keyword about missing data. On the classics, the linear model won three times out of four.

The modelling was never the hard part. Framing the question, preparing the data honestly, measuring the result without fooling yourself, and writing down what it can't do — that's the job, and it's why two of the nine modules were about evaluation and this one is about a document.

See it run

The lesson's code, ready to run and to fiddle with.

Putting the kettle on…

Starting up…

Worked example

not graded

Already written and ready to go — press Run to see what it does, then change a number, a column name, anything, and run it again.

trywriting the LIMITS block for the digits model — what would it be wrong about?

Press Run — the output appears here.

Your turn

3 exercises. Write the code yourself, then press Check — a nudge and the answer are there if you want them.

Gather the facts a card needs from the data itself. Return [rows, features, class_names, class_counts, n_missing] for the breast cancer dataset.

your answer

Confirm the removal. Try to import load_boston and return "removed" if it raises, "present" if it doesn't.

your answer

The track's recurring finding, one last time. Return [linear_r2, forest_r2] on the diabetes data (5-fold), rounded to 4 places — and note which is higher.

your answer