Empirical Risk and Reduction

A loss first judges one example. Training needs one objective for many examples.

For a dataset of n input-target pairs (x_i, y_i), let the model with parameters theta predict f_theta(x_i). If L is the per-example loss, the empirical risk is its average over the observed dataset:

R_hat(theta) = (1 / n) sum_i L(f_theta(x_i), y_i)

“Empirical” means measured on the examples we actually have. It is not the unknown average loss over every future example the model might encounter.

One Dataset Objective by Hand

Suppose three examples have squared errors:

[1, 9, 2]

The common mean reduction gives:

(1 + 9 + 2) / 3 = 4

The sum reduction gives 12, while none keeps [1, 9, 2]. Here each entry is already one loss per example. These reductions contain the same per-example information, but their numerical scale differs. That scale matters later because gradients inherit it.

none -> one loss per example
sum  -> total loss across examples
mean -> average loss across examples

This book uses the mean unless a lesson says otherwise. Averaging makes losses more comparable across batch sizes. It does not make the dataset representative of future data; sampling and generalization remain separate questions.

Exercise: Compute empirical risk

Four examples have per-example losses [0.5, 1.5, 0, 2]. What is their mean empirical loss?

Compute it first, then check your number.

HintUse the mean reduction

Add the four per-example losses, then divide by four.

SolutionReduce the losses

(0.5 + 1.5 + 0 + 2) / 4 = 4 / 4 = 1.

Exercise: Separate mean from sum

A batch contains five examples and its mean loss is 0.4. What is the sum of its per-example losses?

Compute it first, then check your number.

HintUndo the average

Multiply the mean by the number of examples.

SolutionRecover the sum

sum = count * mean = 5 * 0.4 = 2.

Exercise: Know what empirical means

Does low training empirical risk by itself prove low loss on future examples?

Choose one

Select one choice, then check.

HintObserved versus future data

Ask which examples were used to compute the average.

SolutionLimit the claim

No. Low empirical risk describes the observed training data. Generalization to relevant unseen examples must be evaluated separately.