What a Loss Function Measures
A prediction has to be judged against an outcome. The loss function makes that comparison precise: it takes an outcome and a prediction as inputs and returns a numerical penalty. The outcome and the prediction need not be the same kind of object. In regression they are often both real numbers; in probability forecasting the outcome may be a binary label while the prediction is a probability.
This distinction matters because the penalty is not itself an outcome or a prediction. A loss is a rule for assigning a number to a pair. Different rules can assess the same pair differently, and a single rule is defined only for the outcomes and predictions it is designed to handle.
The two input spaces play different roles. The outcome space lists what may actually occur; the prediction space lists what a learning procedure is allowed to report. The loss range records how the chosen rule scores each pairing. Even if \(\mathcal Y\) and \(\mathcal D\) happen to have the same numerical values, they remain distinct roles in the definition.
For example, a regression outcome might be a measured concentration in \(\mathcal Y=\mathbb R\), and a prediction might also be a real number in \(\mathcal D=\mathbb R\). A probability forecast has a different pairing: the outcome can be \(0\) or \(1\), while the prediction lies in \([0,1]\). Treating a probability forecast as though its prediction were the observed binary outcome would confuse the two spaces.
Regression Losses
For a real-valued outcome \(y\) and real-valued prediction \(d\), two familiar choices are squared error and absolute error. They express different numerical penalties for the same discrepancy.
Worked Example: Two Regression Penalties for the Same Prediction
Suppose the observed response is \(y=4\), and a model predicts \(d=7\). Compute both losses.
The signed discrepancy is \(y-d=4-7=-3\), so the absolute discrepancy is \(|-3|=3\). Thus \[ L_{\mathrm{abs}}(4,7)=3. \] The squared discrepancy is \((-3)^2=9\), so \[ L_{\mathrm{sq}}(4,7)=9. \]
The values 3 and 9 are penalties under two different rules; neither is a new outcome or a revised prediction. In particular, the numerical scales are different. One should not compare these values as though the two loss functions shared a common unit.
A loss function can also impose a prediction domain. If the outcome is known to lie in an interval, it may be sensible to restrict predictions to that interval. Alternatively, one can allow predictions outside it and use a loss defined for all real predictions. The domain must be stated: a formula whose prediction input is restricted to \([0,1]\), for instance, is not automatically defined for a prediction of \(1.2\).
Worked Example: Clipping a Regression Prediction
Suppose outcomes lie in \([0,5]\), the observed outcome is \(y=4\), and a model reports \(d=8\). Clipping the prediction to the nearest endpoint gives \(d_{\mathrm{clip}}=5\).
Before clipping, the absolute-error penalty is \[ |4-8|=4, \] and the squared-error penalty is \[ (4-8)^2=16. \] After clipping, the penalties are \[ |4-5|=1 \quad\text{and}\quad (4-5)^2=1. \]
In this case both penalties decrease. More generally, when \(y\in[0,5]\), moving a prediction above 5 down to 5 cannot worsen either penalty; it may decrease it. The corresponding statement holds for predictions below 0 moved up to 0. The guarantee depends on the outcome being in the interval and on using these particular losses.
Probability-Forecast Losses
For a binary event, let the outcome space be \(\mathcal Y=\{0,1\}\), with 1 denoting that the event occurred. A probability forecast is a prediction \(p\in\mathcal D=[0,1]\). The prediction is not a claim that the outcome equals \(p\); it is a reported probability for the event.
Two possible penalties are the squared probability error, also called the Brier loss for a binary outcome, and logarithmic loss. Their inputs are an observed label and a forecast probability.
Worked Example: Scoring Two Binary Forecasts
The event occurs, so \(y=1\). Compare forecasts \(p=0.8\) and \(p=0.4\) under both losses.
For \(p=0.8\), the Brier loss is \[ (1-0.8)^2=0.2^2=0.04. \] The logarithmic loss is \[ -\log(0.8)\approx 0.2231. \] For \(p=0.4\), the Brier loss is \[ (1-0.4)^2=0.6^2=0.36, \] and the logarithmic loss is \[ -\log(0.4)\approx 0.9163. \]
For this realized outcome, both rules assign the smaller penalty to the forecast closer to 1. The numerical values differ because the rules differ. In particular, \(0.04\) and \(0.2231\) are not directly comparable measures of prediction quality across loss functions.
The logarithmic loss is finite for forecasts strictly between 0 and 1, but can be infinite at a boundary when the forecast assigns probability zero to what occurs. This is a feature of the specified penalty, not a problem with the outcome space or with the meaning of a probability forecast. A user choosing this loss should understand that consequence.
Worked Example: Multicategory Outcomes and Probability Vectors
Suppose the possible outcomes are \(\{\text{red},\text{blue},\text{green}\}\). A prediction is a probability vector \(q=(q_{\text{red}},q_{\text{blue}},q_{\text{green}})\), where each component is nonnegative and the components sum to 1. Consider the forecast \((0.2,0.5,0.3)\) and the observed outcome blue.
Represent the outcome by the one-hot vector \(e_{\text{blue}}=(0,1,0)\). The multicategory Brier loss, defined here as the sum of squared component differences, is \[ (0-0.2)^2+(1-0.5)^2+(0-0.3)^2 =0.04+0.25+0.09=0.38. \]
The outcome is the category blue; the prediction is the entire probability vector; and \(0.38\) is the penalty. These are three different objects. The loss formula also makes explicit why a scalar outcome-prediction difference would not be appropriate for these inputs.
Measurability of the Penalty
Measurability ensures that evaluating a loss on measurable random quantities gives a measurable numerical quantity. This matters even before asking about averages or other summaries: without measurability, the loss as a random variable may not be well defined in the usual probability framework.
Proof. First define the paired map \(T:\Omega\to\mathcal Y\times\mathcal D\) by \(T(\omega)=(Y(\omega),D(\omega))\). For a measurable rectangle \(A\times B\), where \(A\in\mathcal A_{\mathcal Y}\) and \(B\in\mathcal A_{\mathcal D}\), \[ T^{-1}(A\times B)=Y^{-1}(A)\cap D^{-1}(B). \] Both sets on the right are measurable, so their intersection is measurable. Since measurable rectangles generate \(\mathcal A_{\mathcal Y}\otimes\mathcal A_{\mathcal D}\), \(T\) is measurable. The composition of measurable maps is measurable, and \(L\circ T\) is exactly \(\omega\mapsto L(Y(\omega),D(\omega))\). Therefore the asserted map is measurable. \(\square\)
For example, if the response \(Y\) and a reported real-valued prediction \(D\) are measurable, then squared-error loss \((Y-D)^2\) is measurable by this result. The proposition does not say that the loss is bounded or has a finite expectation; those are separate questions.
Why the Domain Changes the Claim
A loss is meaningful only together with its domain. In regression, squared error accepts real outcomes and real predictions. In binary probability forecasting, the Brier and logarithmic losses accept binary outcomes and probability predictions. Substituting an input from the wrong space is not a harmless change of notation: it may make the loss undefined or change what is being assessed.
Proof. If \(d\in[a,b]\), then \(c=d\) and equality holds. If \(d<a\), then \(c=a\). Since \(y\geq a>d\), the distances are \(y-a\) and \(y-d\), and \[ |y-c|=y-a\leq y-d=|y-d|. \] If \(d>b\), then \(c=b\). Since \(y\leq b<d\), \[ |y-c|=b-y\leq d-y=|y-d|. \] These cases exhaust the possibilities. Squaring preserves the inequality because both sides are nonnegative, so squared error cannot increase either. The inequality can be strict, as in the worked example with \(y=4\), \(d=8\), and \([a,b]=[0,5]\). \(\square\)
This result has a limited, precise scope: the outcome must belong to the stated interval, the prediction is clipped to its nearest point, and the loss is absolute or squared error. It does not assert that clipping improves every loss, nor that an outcome from outside the interval would satisfy the same comparison.
Common Mistakes
- Confusing outcome and prediction. A probability forecast \(p=0.7\) is not an observed binary outcome. The loss takes both the observed outcome and the forecast as inputs.
- Calling the penalty a prediction error without specifying its rule. Squared error and absolute error assign different numbers to the same outcome-prediction pair.
- Ignoring the domain. A formula defined for probability predictions in \([0,1]\) cannot automatically be applied to a value outside that interval.
- Overstating the clipping result. For outcomes known to be in an interval, clipping an outside prediction cannot worsen absolute or squared error; it may decrease either penalty. This conclusion is not a claim about every possible loss.
- Assuming measurability gives finite penalties. Measurability makes the evaluated loss a measurable quantity. It does not ensure that its value or any later expectation is finite.
Check Your Understanding
Use the definitions and distinctions in this tutorial to answer the following questions.
- For squared-error regression, identify the outcome space, prediction space, and penalty when the observed value is 3 and the prediction is 5.
- In binary probability forecasting, why is a forecast of 0.6 not an outcome in \(\{0,1\}\)?
- What logarithmic loss is assigned to outcome 0 and forecast 1, and why?
- State the measurability conditions that make the loss evaluated at random outcome and prediction measurable.
- If outcomes lie in \([2,10]\), can clipping a prediction of 13 to 10 increase absolute-error or squared-error loss? State the condition on the observed outcome.