Skip to content

Data-Generating Distribution Explained With a Classifier

The data-generating distribution is the single process that draws every training and test example, and a dataset is only one finite sample from it. Goodfellow, Bengio, and Courville set it up in Section 5.2 of Deep Learning. "The training and test data are generated by a probability distribution over datasets called the data-generating process." Then the assumptions: "We typically make a set of assumptions known collectively as the i.i.d. assumptions. These assumptions are that the examples in each dataset are independent from each other, and that the training set and test set are identically distributed, drawn from the same probability distribution as each other." Their name for the shared piece: "We call that shared underlying distribution the data-generating distribution, denoted p_data."

They draw a consequence for error. "The expected training error of a randomly selected model is equal to the expected test error of that model," because both come from the same sampling process. But when a model is chosen after seeing the training set, "the expected test error is greater than or equal to the expected value of training error."

Try it by hand. Let the distribution over one example be this: x is equally likely to be 0, 1, 2, or 3, the label is 1 when x ≥ 2 and 0 otherwise, and each label is then flipped with probability 0.1. That is the whole data-generating distribution. Take a rule that predicts 1 only when x = 3. Under this distribution it is wrong with probability 0.1 at x = 0 and x = 1, with probability 0.9 at x = 2, where the true label is usually 1, and with probability 0.1 at x = 3. Its true error is (0.1 + 0.1 + 0.9 + 0.1) / 4 = 0.30. The rule that predicts 1 for x ≥ 2 has true error 0.10, the noise floor. Now draw datasets of 8 examples. Five draws from this distribution gave the rule a training error of 0.25, 0.50, 0.25, 0.375, and 0.25. Their average over many draws is 0.30, but any one dataset is a noisy glimpse of the distribution, not the distribution. Next let the algorithm choose among the five threshold rules by training error. Over 200,000 datasets of 8, the chosen rule's average training error was 0.088 and its average true error was 0.158: choosing after looking makes the test error larger, as the book says. Last, change the distribution. If deployment sends every example to x = 2, the rule that predicts 1 only for x = 3 is wrong 90% of the time, against 30% before. Nothing about the rule changed, only the distribution it is measured on. I computed the true errors in exact fractions and ran the simulations with NumPy, and the distribution is invented.

The trap: treating a dataset as the distribution, or assuming that deployment will draw from the training distribution. A dataset is a finite sample and cannot specify the process that made it. And training and test error match only in expectation, for a rule fixed before looking at either set: realized errors on finite samples vary, and a rule chosen by its training error looks better, on average, on the training data than it will on new data even when both sets come from the same distribution, as the 0.088 against 0.158 above shows. A caution of my own, not from the section I read: the i.i.d. assumptions are two separate assumptions, independence and identical distribution, and real data often break one of them, for example through time order or through how the examples were selected.

Prof Rod's rule: say which distribution an error was measured on, expect it to describe deployment only if deployment draws from the same one, and treat one dataset as one draw.

Goodfellow, Bengio, and Courville, Deep Learning, MIT Press, 2016, Section 5.2, p. 109