learn-two-cultures-with-phoebe / Session 3 of 6
Learn The Two Cultures with Phoebe · Session 3 of 6

Explore first, confirm once

In 1962 John Tukey opened a 67-page paper in the Annals of Mathematical Statistics by admitting that he was no longer sure he was a statistician. What he cared about, he wrote, was data analysis, and he argued that it was a science in its own right, judged by the test of experience rather than by proof. His 1977 book is reported to have given the exploring half a name of its own, and a 1980 paper put the whole argument in its title: we need both exploratory and confirmatory. Tonight we read the 1962 paper at source, separate what it says from what it is quoted as saying, and then run the discipline on 569 real biopsies: explore 398 rows as freely as you like, and open the other 171 exactly once.

🟠 Advanced Leaders and practitioners Python, pandas 45 min
0-3 · Welcome 3-18 · Tukey, the detective and the judge 18-40 · Build-along: explore the 398, confirm on the 171 once 40-45 · Q&A
Part 0

Where we start

Sessions 1 and 2 kept one habit without naming it: 171 biopsies were set aside before any model existed, and every score was read off them. Tonight names the habit and its author. Tukey did not invent the held-out set, but he drew the line it depends on: one kind of work where you are allowed to look at anything and change your mind as often as you like, and a second kind where you state one claim in advance and test it once. The two colours still mean what they meant: ochre for the data modelling culture, violet for the algorithmic culture. Tonight's figures are mostly about rows, not cultures, so terracotta does most of the talking.

🎫 Clear all three quiz questions to stamp your passport Live = presented in the 45 minutes Self-study = the full depth, after class ★ Build-along = run the code yourself

★ What you walk out with tonight. Tukey's three-part test of a science, in his words, and why mathematics fails it; the difference between what the 1962 paper actually says and what later books and slides attribute to it; a clear rule for what exploration may do and what confirmation may do; and a pandas script that finds a rule on 398 training rows, writes it down, and grades it once on 171 untouched rows, next to two peeks that score higher and prove nothing.

Part 1 · covers Tukey 1962, data analysis as a science

A statistician who stopped being sure

6 min live

"The Future of Data Analysis" is not a methods paper. It is a job description for a field that did not yet have a name, and it argues that the field's standard of truth should be experience, not proof. The whole claim rests on a three-part definition, and the figure below draws it as three gates.

TUKEY'S TEST OF A SCIENCE, 1962 three constituents, pp.5-6: a field has to pass all three gates a1 a2 a3 intellectual content organization understandable test of experience ultimate standard mathematics data analysis not a science judged by proof a science defined by a ubiquitous problem rocky road, p.64 WHAT PASSING GATE a3 COSTS, p.6 (b1) scope and usefulness rather than security · (b2) willing to err moderately often (b3) mathematical results as bases for judgment, not as bases for proof Mathematics passes a1 and a2 and stops at a3: it is judged by proof, not by the test of experience.
🔍 Click to zoom - the terracotta gate is the whole argument: a field whose final judge is experience cannot also demand the security of proof
LiveThe confession, and the three gates4 min▶

The paper's first page of argument is personal. "For a long time I have thought I was a statistician, interested in inferences from the particular to the general. But as I have watched mathematical statistics evolve, I have had cause to wonder and to doubt." (Tukey, 1962, p.2). He then says what he cares about instead: "my central interest is in data analysis, which I take to include, among other things: procedures for analyzing data, techniques for interpreting the results of such procedures, ways of planning the gathering of data to make its analysis easier, more precise or more accurate, and all the machinery and results of (mathematical) statistics which apply to analyzing data."

To claim data analysis is a science he needs a definition of science, and he gives one with three constituents (pp.5-6): "(a1) intellectual content, (a2) organization into an understandable form, (a3) reliance upon the test of experience as the ultimate standard of validity." Then the sentence that must have stung his readers: "By these tests, mathematics is not a science". Mathematics has content and organisation, but its standard of validity is proof. Data analysis, he argues, passes all three, and is "a science, one defined by a ubiquitous problem rather than by a concrete subject."

Gate a3 has a price, and he states it on p.6. "(b1) Data analysis must seek for scope and usefulness rather than security." (b2) It "must be willing to err moderately often in order that inadequate evidence shall more often suggest the right answer." (b3) It "must use mathematical argument and mathematical results as bases for judgment rather than as bases for proof or stamps of validity." Hold on to (b2): a discipline that is allowed to err moderately often needs somewhere to find out when it has.

Self-studyThe right question, sanctification, and a quote that is not there4 min▶

The most quoted sentence. Section 11, "Facing uncertainty" (pp.13-14): "Far better an approximate answer to the right question, which is often vague, than an exact answer to the wrong question, which can always be made precise." D. R. Cox, replying to Breiman in 2001, gives a close cousin: "Better a rough answer to the right question than an exact answer to the wrong question, an aphorism, due perhaps to Lord Kelvin". Same idea, two attributions; Cox's "perhaps" is his, and nobody has settled the origin here. How you choose the right question in the first place is its own discipline, taught in Data Thinking, session 3 ↗.

The danger he names. On p.13 Tukey warns against "the use of formal data-analytical procedures for sanctification, for the preservation of conclusions from all criticism, for the granting of an imprimatur." A significance test run to bless a conclusion already reached is exactly that. Keep the word; Part 3 shows what sanctification looks like in numbers.

The attribution trap. David Donoho's 2017 "50 Years of Data Science" quotes a list, "Four major influences act on data analysis today", right after his quotations from this paper; a full-text search of the whole 1962 paper, pages 1 to 67, finds no such list, so it can only be cited as a list Donoho attributes to Tukey, source unconfirmed. That is the professional habit this session is about, applied to text: a quote is a hypothesis until you have read it at source.

Real world

"Live with the data before you plunge into modeling." Leo Breiman spent thirteen years as a free-lance consultant before joining Berkeley in 1980, on projects such as forecasting ozone for the EPA from more than 450 weather variables. When he left consulting, this was the second of the five perceptions he took back to the university (Breiman, 2001, p.201). Tukey's closing line in 1962 asks for the same temperament from a whole profession: "the rocky road of real problems in preference to the smooth road of unreal assumptions, arbitrary criteria, and abstract results without real attachments. Who is for the challenge?" (p.64).

Part 2 · covers exploratory versus confirmatory

The detective and the judge

5 min live

The popular story is that Tukey's 1962 paper launched exploratory data analysis. Read at source, it does something subtler. It never uses the words "exploratory data analysis" as a named practice, and it keeps the other half on purpose: Tukey says we should go on "using statistical techniques for the confirmatory appraisal of observations through such conclusion procedures as confidence statements and tests of significance" (p.7). The named pairing came later, and the dates matter when you quote him.

THE DETECTIVE AND THE JUDGE two jobs, two sets of rows, and a valve that only opens one way EXPLORE · the 398 training rows many looks, many hypotheses, as often as you like 398 rows radius? area? texture? a cut here? a plot write it down one way only CONFIRM · the 171 untouched rows one pre-stated test, run once 171 held out one test one number no new cut, no second feature, no rerun the number is the result, good or bad back through the valve: a peek Anything goes on the left. On the right, a second look turns the judge back into a detective.
🔍 Click to zoom - the terracotta valve is the moment the hypothesis is written down; the dashed arrow is the one move that is never allowed
LiveThree dates, two tiers of evidence2 min▶

1962, read at source. Data analysis as a science; "confirmatory appraisal" kept, once, on p.7; the words "exploratory data analysis" do not appear as a named practice. On the same page Tukey quotes Martin Wilk: "The hallmark of good science is that it uses models and 'theory' but never believes them."

1977, reported. The book Exploratory Data Analysis (Addison-Wesley) is widely described as casting exploration as detective work. It was not opened for this session, so treat that description as reported.

1980, reported, title only. "We Need Both Exploratory and Confirmatory", The American Statistician 34(1). The title itself is the claim tonight teaches; the text was not opened here.

Donoho, writing in 2017 and read at source, is where the detective metaphor reaches today's data science: "Since John Tukey's coining of the term 'exploratory data analysis' (EDA), we all agree that every data scientist devotes serious time and effort to exploring data ... Such detective work adds crucial insights to every data-driven endeavor."

LiveWhat exploration is allowed to do1 min▶

Anything, as long as it happens on the exploration rows. Plot every feature. Compare class means. Try every cut on every column. Change your mind ten times. Tukey's own words from p.4 describe the attitude: "we need to stress flexibility of attack, willingness to iterate, and willingness to study things as they are, rather than as they, hopefully, should be."

What exploration produces is not a result. It is a hypothesis, and its training score is a rumour: the rows that suggested the rule are the rows that score it, so the score is flattered by construction.

Self-studyWhat confirmation is allowed to do2 min▶

One pre-stated test, once. Before the confirmation rows are opened, write down the rule, the metric and what would count as failure. Then run it and report what it printed, even when it is disappointing.

Everything else is off limits: re-choosing the cut, swapping to a feature that "looks better here", dropping the rows that disagree, or rerunning with a new seed until the number is pleasant. Each of those moves a decision to the wrong side of the valve, and the rows stop being a judge. If you genuinely learned something from the confirmation, the honest move is to treat it as exploration and find fresh rows to confirm on. What a single test score then entitles you to claim is a question with its own session: ML Epistemology, leader session 1 ↗.

Real world

Two years nobody touched. In Breiman's EPA ozone project in the mid-1970s, the job was to predict the next day's ozone in the Los Angeles Basin from over 450 meteorological variables. Seven years of data were available. The first five years were used to build the predictor; the last two were set aside as the test set (Breiman, 2001, pp.200-201). Whatever happened on the five years was detective work. The two years were the judge.

Part 3 · covers why the confirmatory set must be untouched

A peek is a search the judge helped with

4 min live

Nobody sets out to cheat. The damage comes from small, sensible-looking moves: glance at the test score, adjust one setting, glance again. Bruce Hoadley, of the credit-scoring company Fair, Isaac, described it in his 2001 reply to Breiman as "The algorithm tuning dilemma", and it is the reason the rows that confirm must be sealed before the exploring starts.

THE SAME SEARCH, ON THE WRONG ROWS AND ON THE RIGHT ONES WRONG WAY · search on the 171 every feature, every cut, chosen by the rows that grade it search the 171 all 30 features worst concave points picked by the 171 163 of 171 the best score on the page the same rule on the 398 training rows: 354 of 398 worse than worst radius there (367): the 171 chose it RIGHT WAY · explore on the 398 search freely, write it down, open the 171 once search the 398 all 30 features worst radius <= 16.76: 367 of 398 157 of 171 lower, and the only honest number the hypothesis was written before the 171 one test, run once: whatever it printed was the result 163 beats 157 on the page and loses on the rows it never chose from. Choosing on the grader is fitting to it.
🔍 Click to zoom - the terracotta box is the tell: a rule the held-out rows picked does worse than the honest rule on rows they did not see
LiveThe tuning dilemma, and the drift behind it2 min▶

Hoadley (2001, p.223): "in industry and academia, there is sometimes a little tinkering, which involves peeking at the test sample. The result is some bias in the test sample or cross-validation results." And the question every modelling team faces: "How do you optimize your results and get an unbiased estimate of the generalization error?" The answer is not to stop tuning. It is to tune on rows that will never grade you.

He adds a second reason the judge must be honest: even a clean test score "does not guarantee high performance on future samples, things do change" (pp.221-222), and Fair, Isaac redevelops its core models about every 18 to 24 months. An inflated number today is also the baseline you will measure next year's drift against.

The field later built this seal into its institutions. In Donoho's account of the common task framework, the referee's test set "is sequestered" and scored automatically, so no competitor can peek. Session 5 reads that history in full.

Self-studyWhat the peek does to our two models2 min▶

The session 4 bench has a "peek" rung: grade each model on the 398 rows it was fitted on instead of the 171 it never saw. The forest scores 398 of 398 (100.0 percent) on the rows it memorised, against 167 of 171 (97.7 percent) held out. That gap is what peeking hides.

The regression goes the other way: 392 of 398 on training (98.5 percent) but 170 of 171 held out (99.4 percent). A held-out set of 171 rows can flatter as well as punish: one biopsy is 0.6 points. The lesson is not that held-out scores are exact. It is that they are the only scores nobody has had a chance to steer, so they are the only ones allowed to carry the claim, with their small-sample wobble stated beside them.

Real world

A later judge, three times over. Hoadley's Fat Scorecard, the credit model whose 162 score weights had confidence intervals he called "useless", was not left to its original test sample. It had three extra test samples taken one, two and three years later (Hoadley, 2001, p.222), and it held up. That is what an honest later confirmation looks like: fresh rows, gathered after the model was fixed, that nobody could have tuned against.

Build-along

Explore the 398, confirm on the 171 once

★ 22 min · everyone builds

Same biopsies, same split as sessions 1 and 2: the UCI Breast Cancer Wisconsin (Diagnostic) set, 569 biopsies, 30 nucleus measurements each, split once with seed 2001. This time there is no model library. You explore the training rows with pandas, hunt for the best single-feature rule by hand, write the hypothesis down, open the held-out rows once, and then commit the two classic sins on purpose so you can see what they print. Every output below is what the code prints.

THE BUILD-ALONG, ONE WAY THROUGH steps 1 to 4 see only the 398; step 5 opens the 171, once 398 rows exploration only class means best single cut write it down before the 171 open the 171 once 157 of 171 worst radius 367 of 398 cut 16.76, benign if <= no new cut no second feature steps 6 and 7 walk back: 158 and 163, neither a result Everything left of the terracotta box may be rerun as often as you like. Nothing right of it may.
🔍 Click to zoom - the terracotta box is a comment in your script, and it is the most important line you will write tonight

Load the biopsies and make the same split as session 1. Thirty percent of each class is set aside with seed 2001. From here until step 5, the variable test is a list of row numbers you do not look at.

★ Step 1 · split, as in session 1import numpy as np import pandas as pd from sklearn.datasets import load_breast_cancer data = load_breast_cancer() X, y = data.data, data.target # y: 1 = benign, 0 = malignant names = list(data.feature_names) rng = np.random.default_rng(2001) test = [] for cls in (0, 1): idx = np.flatnonzero(y == cls) test += list(rng.permutation(idx)[: round(0.30 * len(idx))]) test = np.array(sorted(test)) train = np.setdiff1d(np.arange(len(y)), test) print(len(train), len(test)) # 398 171

Explore: class means, training rows only. Put the 398 rows in a DataFrame and compare the two classes on three features. Malignant nuclei are bigger and more concave; that is the first clue, not a conclusion.

★ Step 2 · the detective's first lookdf = pd.DataFrame(X[train], columns=names) df["benign"] = y[train] print(df.groupby("benign")[["worst area", "worst concave points", "mean texture"]].mean().round(3)) # worst area worst concave points mean texture # benign # 0 1360.329 0.178 21.597 # 1 565.400 0.075 17.905

Explore harder: the best single-feature rule. For every feature, try every observed value as a cut, in both directions, and count how many training biopsies the rule gets right. Keep the top three. This is a brute-force search, and on the exploration rows it is completely allowed.

★ Step 3 · search the 398def best_rule(rows, j): v, t = X[rows, j], y[rows] best = (0, None, None) for c in np.unique(v): for side in (0, 1): pred = (v <= c).astype(int) if side == 0 else (v > c).astype(int) ok = (pred == t).sum() if ok > best[0]: best = (ok, c, side) return best res = sorted(((best_rule(train, j), names[j], j) for j in range(30)), key=lambda z: -z[0][0])[:3] for (ok, c, side), n, j in res: print(n, ok, "of", len(train), "cut", c, "benign if <=" if side == 0 else "benign if >") # worst radius 367 of 398 cut 16.76 benign if <= # worst area 367 of 398 cut 867.1 benign if <= # worst perimeter 365 of 398 cut 109.8 benign if <=

Write the hypothesis down before the 171 exist for you. This step prints nothing and matters most. Worst radius and worst area tie on 367; the sort keeps worst radius first, and you commit to it now. State the rule, the metric and the bar it has to clear, in a comment that will still be in the file when someone reviews it.

★ Step 4 · the valve# HYPOTHESIS, written before the held-out rows are opened: # rule: benign if worst radius <= 16.76, malignant otherwise # metric: biopsies right, out of the 171 held out # bar: beat the base rate of 62.6 percent (session 1) # One test. One run. Whatever it prints is the result. (ok, c, side), n, j = res[0]

Confirm once. Apply the written rule, unchanged, to the 171 held-out biopsies. It is lower than the 367 of 398 it earned in exploration, and that drop is information: it is what a training score was hiding.

★ Step 5 · the judgepred = (X[test, j] <= c).astype(int) if side == 0 else (X[test, j] > c).astype(int) print("confirm once:", n, "<=", c, (pred == y[test]).sum(), "of", len(test)) # confirm once: worst radius <= 16.76 157 of 171

Sin on purpose, small: re-choose the cut on the held-out rows. Same feature, but let the 171 pick the threshold. It gains one biopsy. That one biopsy is not evidence about worst radius; it is the held-out rows fitting themselves.

★ Step 6 · the small peekokp, cp, sp = best_rule(test, j) print("peek cut", cp, okp, "of", len(test)) # peek cut 15.85 158 of 171

Sin on purpose, big: search every feature and cut on the held-out rows. Now the 171 choose the feature as well. The winner scores 163, the best number you will see tonight. Then check it on the 398 rows it never chose from: it does worse there than the worst radius rule you found honestly.

★ Step 7 · the big peekallp = max(((best_rule(test, k)[0], names[k]) for k in range(30))) print("best of 30 features chosen on held-out:", allp) # best of 30 features chosen on held-out: (163, 'worst concave points') k = names.index(allp[1]); okk, ck, sk = best_rule(test, k) predtr = (X[train, k] <= ck).astype(int) if sk == 0 else (X[train, k] > ck).astype(int) print("same rule on training rows:", (predtr == y[train]).sum(), "of", len(train), "cut", ck) # same rule on training rows: 354 of 398 cut 0.1288

Report 157, not 163. The peeked rule looks six biopsies better on the 171 and is thirteen biopsies worse on the 398 than the rule you wrote down. The held-out rows stopped being a judge the moment they chose the feature. If you want to know whether worst concave points really is better, that is now a hypothesis, and it needs rows that have not voted yet.

Homework

Before session 4

30 min
  1. Read the first seven pages of Tukey's 1962 paper, through the "confirmatory appraisal" passage on p.7. Mark every sentence about what data analysis should be allowed to do, and every sentence about what it must still check.
  2. Check one quote at source. Take a Tukey, Box or Breiman quotation you have seen on a slide or a post. Find it in the primary text. If you cannot, rewrite your citation as "attributed to" or "reported", the way the four major influences list has to be cited.
  3. Run the valve with a different hypothesis. Before touching the 171, write down worst area <= 867.1 as your rule in the step 4 comment, then run step 5 for it once. Write down what it prints, and do not change the rule afterwards.
  4. Find a peek at work. Pick one number from a recent report or deck and ask who chose the model, the threshold or the segment, and on which rows. If the same rows chose it and scored it, write the one-line hypothesis that should have been written first.
Check yourself

Three questions

Clear all three and session 3 gets stamped in your passport.

1 · A slide says "Tukey coined exploratory data analysis in his 1962 paper and listed four major influences on data analysis." What does the 1962 paper, read at source, actually contain?

The 1962 paper is the programme; the named practice came later. A secondary source quoting a list right after a paper's quotations is not proof the list is in that paper, which is why a quote stays a hypothesis until it is read at source.

2 · In the build-along, a search over all 30 features on the held-out rows finds worst concave points at 163 of 171, beating the written-down rule's 157. Why is 163 not a result?

A score is only a judge's verdict when the judge had no hand in picking the defendant. Hoadley calls the mild version "a little tinkering, which involves peeking at the test sample", and says the result is bias.

3 · The logistic regression scores 392 of 398 on its own training rows and 170 of 171 held out. Why can the held-out score beat the training score?

Held-out scores are unsteered, not exact. Redrawing the split until it looks right would be a peek of its own, the same sin as step 7 with a different lever.

Sources covered

What this session teaches, and where it came from

✓Tukey (1962), The Future of Data AnalysisAnnals of Mathematical Statistics 33(1), 1-67; read at source from a full scan, every quotation checked against the printed page (pp.2, 4, 5-6, 7, 13-14, 64)
◐Tukey (1977), Exploratory Data Analysis, and Tukey (1980), We Need Both Exploratory and ConfirmatoryReported only: the book's "detective work" framing and the 1980 title are cited as widely described, neither text was opened
✓Donoho (2017), 50 Years of Data ScienceJournal of Computational and Graphical Statistics 26(4), 745-766; read at source for the EDA and detective work passage and the sequestered test set
✓Hoadley's comment on Breiman (2001)Statistical Science 16(3), 220-224; read at source for the tuning dilemma, drift and redevelopment cycle, and the Fat Scorecard's later test samples
◐The "four major influences" listQuoted by Donoho after his 1962 quotations; not found in a full-text search of the 1962 paper, so cited only as attributed, source unconfirmed
✓The build-along on UCI Breast Cancer Wisconsin (Diagnostic)Wolberg, Mangasarian, Street and Street (1993), UCI Machine Learning Repository, doi 10.24432/C5DW2B, CC BY 4.0; every printed output produced by the code on scikit-learn 1.9.0 and pandas

Every fact on this page, and its verification tier, is recorded in the course's source map.

Session 3 cheat sheet · pin this

Three gates of a science(a1) content, (a2) organisation, (a3) the test of experience. Mathematics stops at a3; data analysis passes.
The price of a3"Seek for scope and usefulness rather than security", and be willing to err moderately often.
Detective, then judgeExplore anything on the exploration rows. Confirm with one pre-stated test on untouched rows, once.
Write it down firstRule, metric and bar in a comment before the held-out rows open. Worst radius: 367 of 398, then 157 of 171.
A peek is not a resultChosen on the 171: 163 of 171, but only 354 of 398 on rows it never chose from.
Check the quote at source1962 is the programme; 1977 and 1980 name the pairing (reported). The four influences list is not in 1962.