The Formal Learning Problem
Imagine you want a program that looks at a medical scan and predicts whether a tumor is malignant. You have a few thousand past scans, each labeled by a radiologist. But you need the program to work correctly on scans it has never seen. This is the central puzzle of machine learning, stated without any algorithm yet in sight. What, precisely, are we trying to compute? How do we know when we have succeeded? Before we can discuss decision trees, neural networks, or support vector machines, we need a language precise enough to say what "success" even means. This precision matters enormously in practice. Every production ML system — a fraud detector, a recommendation engine, a self-driving perception stack — is a bet. It bets that patterns observed on past data will hold on future data. If that bet is not framed carefully, a system can appear to work perfectly in testing. Then it can fail catastrophically in deployment. The formal learning problem gives us the vocabulary to state the bet explicitly. We need an input space, an output space, an unknown probability distribution linking them. We also need a loss function that measures the cost of being wrong, and a risk we are trying to minimize. The big picture is this: learning is not curve-fitting for its own sake. It is decision-making under uncertainty about a distribution we cannot see directly. We only get a finite sample from that distribution. Yet we want a rule that performs well on the entire distribution. This includes points we will never observe during training. This gap between what we can measure (performance on a sample) and what we actually care about (performance on the distribution) is the single deepest idea in learning theory. It recurs in every later topic — overfitting, regularization, generalization bounds, cross-validation. This article builds the formal skeleton on which all of supervised learning hangs. It covers the definitions of input/output spaces, the unknown joint distribution, loss functions, and the risk functional we would minimize if we could. It sets up, but deliberately stops short of, the practical machinery. That machinery — Hypothesis Spaces and the distinction between Training Error vs Test Error — is built by later articles on top of this foundation.
- Learning means choosing a function from a data-generating process we cannot observe directly.
- Data is assumed to come i.i.d. from an unknown joint distribution over inputs and outputs.
- A loss function quantifies the cost of predicting when the truth is .
- The risk is the quantity we truly want to minimize.
- Because is unknown, we minimize the empirical risk on a finite sample instead — a proxy, not the goal.
- The gap between empirical and true risk is exactly what later ideas like overfitting and generalization address.
Learning is the search for a function that minimizes expected risk over an unknown distribution, using only a finite sample drawn from it as a stand-in for that distribution.
The idea
Formally, a learning problem is built from a small number of ingredients. The input space is the set of all possible inputs — images, feature vectors, sequences, sensor readings. The output space is the set of possible answers: a finite set of labels for classification, an interval of for regression, or a structured object for structured prediction. A hypothesis, or predictor, is a function (or, more generally, producing a score that is later thresholded or ranked). The crucial and easily overlooked assumption is that the pairs we observe are not arbitrary. We posit an unknown joint probability distribution over , and we assume the training data consists of samples drawn independently and identically distributed (i.i.d.) from . This single assumption is what makes learning from a finite sample meaningful at all: without some stable, repeatable regularity governing how inputs and outputs co-occur, no amount of past data could say anything about future data. Note that need not be deterministic — the same can produce different with different probabilities, reflecting real label noise (two radiologists might disagree on a borderline scan). To measure how bad a wrong prediction is, we introduce a loss function , where is the penalty for predicting when the true value is . Common choices include the 0-1 loss for classification, and the squared loss for regression. The loss function is a modeling choice — it encodes what "wrong" costs, and different applications (e.g. a false negative in cancer screening versus a false positive in spam filtering) may demand very different loss functions even on the same data. With these three ingredients — — and a loss , we can finally define the object learning theory revolves around: the expected risk (also called the true risk or generalization risk) of a hypothesis ,
The formal learning problem is to find
over some class of admissible functions (a topic taken up in Hypothesis Spaces). The unattainable ideal, over all measurable functions, is called the Bayes optimal predictor; its risk is the Bayes risk, the fundamental floor of error that not even infinite data and infinite compute can beat, because it is driven by irreducible noise in itself.
How it works
There is no "algorithm" for the formal learning problem itself — it is a specification, not a procedure. But it is worth walking through, step by step, exactly how this specification is turned into something computable, because the translation from the ideal (unknown ) to the practical (a finite sample) is the mechanism every learning algorithm actually implements.
Step 1 — Define the spaces. Fix (e.g., for feature vectors) and (e.g., for binary classification, or for regression).
Step 2 — Posit the distribution. Assume there is a fixed, unknown generating all data of interest, past and future. We never get to see ; we only see samples from it.
Step 3 — Choose a loss. Pick appropriate to the task and its real-world costs.
Step 4 — State the ideal objective. The true goal is . This cannot be computed directly since is unknown — there is no way to take an expectation over a distribution you cannot write down.
Step 5 — Approximate with a finite sample. Draw . Replace the true distribution with the empirical distribution that places mass on each observed point. This yields the empirical risk:
Step 6 — Minimize the proxy. Every concrete learning algorithm (linear regression, logistic regression, a neural network trained by backpropagation, a decision tree splitting criterion) is, at heart, an optimization procedure that approximately solves
over some restricted hypothesis class (never all measurable functions — that would let the optimizer memorize the sample with zero empirical risk while learning nothing generalizable). This restriction is the subject of Hypothesis Spaces.
Step 7 — Hope, and later verify, that tracks . The entire theoretical apparatus of generalization bounds exists to control the gap , which is exactly the subject taken up under Training Error vs Test Error. ``` ALGORITHM: EmpiricalRiskMinimization(D, F, L) Input: D = {(x_1, y_1), ..., (x_n, y_n)} // i.i.d. sample from unknown P F // hypothesis class (restricted!) L // loss function // Step 1: define the computable proxy for the true risk define R_hat(f) := (1/n) sum_{i=1..n} L(y_i, f(x_i)) // Step 2: search F for a minimizer of the proxy f_hat := argmin_{f in F} R_hat(f) // Step 3: return the learned predictor return f_hat // NOTE: R(f) = E_{(x,y)~P}[L(y, f(x))] is NEVER computed here — // P is unknown. R_hat(f) is the only quantity the algorithm // ever touches. The entire theory of generalization is about // how well R_hat(f_hat) approximates R(f_hat), and how far // R(f_hat) is from R(f) = min_{f in F} R(f). ``` The pseudocode above is deliberately generic: whether is the set of linear functions, decision trees of depth , or a fixed-architecture neural network, and whatever optimizer is used (closed-form least squares, gradient descent, greedy tree splitting), the shape of the problem is always: minimize an empirical average of losses in place of an unreachable expectation. This is why the formal learning problem is foundational — it is the common abstraction underlying every algorithm covered elsewhere in the curriculum.
Complexity & correctness
Complexity. The formal learning problem itself has no algorithmic complexity — it is a mathematical statement, not a procedure — but the empirical-risk-minimization proxy that instantiates it does. Given samples in :
- Computing for a fixed costs loss evaluations, each to depending on how is computed, giving total for one evaluation of the empirical risk.
- Minimizing over is where all the real cost lives, and it is entirely algorithm-dependent: closed-form linear least squares costs via normal equations; gradient-based methods cost per iteration times the number of iterations; tree-based greedy splitting costs per level. None of this complexity is dictated by the formal learning problem itself — it is dictated by the choice of and optimizer, which is exactly why the problem statement is deliberately separated from the algorithm.
- Space is to hold the sample, plus whatever the hypothesis class needs to store its parameters (e.g., for a linear model, for a tree).
The one complexity fact that is intrinsic to the formal learning problem is statistical, not computational: as , under mild regularity conditions, almost surely for any fixed , by the strong law of large numbers, since is literally a sample average of the i.i.d. random variables . The rate of this convergence, uniformly over an entire hypothesis class rather than a single fixed , is governed by concentration inequalities and complexity measures of (VC dimension, Rademacher complexity) — this is precisely the machinery developed under Training Error vs Test Error and is foreshadowed, not derived, here.
Correctness. What does "correctness" even mean for a specification with no algorithm? It means the following chain of reasoning holds: 1. Well-posedness: because are i.i.d. draws from a single fixed , the quantity for fixed is itself an i.i.d. sequence of real-valued random variables with mean . This is what licenses calling an unbiased estimator of :
2. Consistency for a fixed : by the law of large numbers, in probability (and almost surely) as , for any fixed with finite loss variance. 3. The subtlety: point 2 holds for one fixed chosen before seeing the data. But empirical risk minimization chooses after seeing the data, specifically to make small — so is a biased (optimistically low) estimate of . This is the formal origin of overfitting, and it is exactly why in general, and why held-out test data is needed to estimate honestly. This tension is the seed from which Training Error vs Test Error grows. 4. Bayes-optimality as ground truth: for 0-1 loss and known , the function provably minimizes over all functions — a fact provable by pointwise minimization of the conditional risk for each independently, since the overall risk is an expectation (integral) over of these conditional risks, and each is minimized independently by choosing the most probable class. This gives a concrete, checkable sense in which the formal setup is "correct": it recovers exactly the intuitively right answer (predict the most likely label) when is fully known.
Honest tradeoffs. The formal framework assumes i.i.d. data from a fixed distribution — violated by distribution shift, temporal drift, or adversarial adaptation, all common in deployed systems. It also assumes the loss function fully captures real-world costs, which is often only an approximation (e.g., 0-1 loss ignores calibration, squared loss is sensitive to outliers). None of these are flaws in the framework so much as reminders that it is an idealization whose assumptions must be checked against reality.
Worked example
Consider a tiny, fully concrete instance to make every symbol tangible. Suppose small, medium, large (house sizes, categorical) and (0 = "sells under $300k", 1 = "sells over $300k"). Suppose, purely for illustration, that the true (unknown, in reality) joint distribution is:
| small | 0.5 | 0.10 |
| medium | 0.3 | 0.60 |
| large | 0.2 | 0.95 |
We use 0-1 loss: . If we knew (which real learners never do), the Bayes-optimal classifier predicts the majority label per : for small (), for medium and large. Its Bayes risk is:
Even the best possible classifier is wrong 18% of the time — this is irreducible noise, not a flaw of any algorithm. Now suppose we don't know ; we only observe a sample of houses drawn i.i.d. from it:
| 1 | small | 0 |
| 2 | small | 0 |
| 3 | small | 0 |
| 4 | small | 1 |
| 5 | medium | 1 |
| 6 | medium | 0 |
| 7 | medium | 1 |
| 8 | large | 1 |
| 9 | large | 1 |
| 10 | large | 0 |
Consider the hypothesis class all functions constant on each of the three categories (equivalent to possible predictors, one bit per category). Empirical risk minimization picks, for each category, whichever label is the sample majority within that category:
- small: labels → majority 0, empirical error contribution within-group.
- medium: labels → majority 1, empirical error contribution within-group.
- large: labels → majority 1, empirical error contribution within-group.
This exactly recovers , , — matching the true Bayes rule in this case, purely because happened to be large enough for majorities to align. The empirical risk is:
Notice : the empirical risk on this particular small sample overestimates the true risk here (it could equally have underestimated it with different random draws), illustrating concretely that is only a noisy, sample-dependent proxy for — exactly the point the LLN-based argument made abstractly above. With , sampling noise is large; as grows toward thousands, the law of large numbers guarantees will concentrate tightly around the true risk of whatever function is learned — the quantitative rate of that concentration is the subject taken up next in Training Error vs Test Error.
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Treating as if it equals | Conflating the computable proxy with the true objective | False confidence; the model looks great on training data but fails in deployment |
| Assuming the loss function is "obviously correct" | Defaulting to 0-1 or squared loss without checking real costs | Misaligned incentives, e.g. penalizing false positives and false negatives equally when they are not equally bad |
| Ignoring the i.i.d. assumption | Data collected over time, geography, or with feedback loops | Distribution shift silently invalidates the entire formal setup |
| Choosing = all functions | Believing "more flexible is always better" | Empirical risk can be driven to zero by memorization, with no bearing on true risk |
| Forgetting the Bayes risk floor | Expecting a perfect model to exist | Wasted effort chasing zero error when noise in makes it mathematically impossible |
| Re-using the same sample to both fit and evaluate | No separate estimate of is available | Systematically optimistic risk estimates, the seed of overfitting analysis |
Pioneers & history
The formal learning problem as stated here — unknown distribution, loss function, expected risk — crystallized out of decades of work bridging probability theory, statistics, and computer science.
Origins · 1 minAndrey Kolmogorov and how this was discovered
Kolmogorov's 1933 axiomatization of probability gave the rigorous foundation — probability spaces, random variables, expectation as an integral — without which terms like "unknown distribution " and "expected risk " would have no precise meaning at all.
:::physicist[Vladimir Vapnik|born 1936|co-creator, with Alexey Chervonenkis, of statistical learning theory| Vapnik formalized empirical risk minimization as the central object of learning theory and, with Chervonenkis, developed VC dimension to explain when and why minimizing empirical risk over a restricted hypothesis class controls the true risk — directly foreshadowing the next topic in this sequence.
Origins · 1 minhow this was discovered
Where this matters
Every supervised learning system deployed today is, underneath its specific architecture, an instance of empirical risk minimization standing in for the formal learning problem. Search ranking systems minimize a proxy for the risk of showing irrelevant results; recommendation engines minimize a proxy for the risk of recommending items users won't engage with; medical diagnosis models minimize a proxy for the risk of misclassifying a scan, often with an asymmetric loss that penalizes missed cancers far more than false alarms. Autonomous vehicle perception stacks are trained by minimizing empirical risk over enormous labeled datasets, with the entire safety case resting on the (imperfect) assumption that deployment-time driving conditions resemble the training distribution. The formal framework also underlies the theoretical guarantees that regulators and engineers increasingly demand: PAC-learning bounds, generalization certificates, and risk-based model cards all trace back to this same skeleton — an unknown , a loss , a true risk , and an empirical proxy . Understanding this skeleton is what lets a practitioner diagnose why a model that looked perfect in a notebook fails in production: almost always, it is because and silently diverged, a phenomenon the next articles on Hypothesis Spaces and Training Error vs Test Error explain in full quantitative detail. It is also the conceptual backbone connecting supervised learning to the broader landscape introduced in Types of Learning: Supervised, Unsupervised, Reinforcement, since even unsupervised and reinforcement learning formulations define analogous risk functionals over their own respective distributions and loss (or reward) structures.
Ask the tutor: If the empirical risk is a biased estimate of the true risk once we've chosen the minimizing hypothesis, how do held-out test sets and cross-validation actually fix this problem?
Is the "unknown distribution" assumption realistic, or just a convenient fiction?
It is a genuine modeling idealization, but a useful and largely necessary one. In reality, data-generating processes may drift over time, differ by subgroup, or be affected by feedback loops from the model's own predictions — all violations of the fixed-, i.i.d. assumption. Despite this, assuming a fixed unknown gives a tractable starting point from which deviations (distribution shift, non-stationarity, selection bias) can be explicitly studied and corrected for, rather than left implicit and unexamined. Nearly all of statistical learning theory, and the diagnostic tools practitioners use daily (train/validation/test splits, cross-validation, monitoring for drift), exist specifically to detect and manage violations of this idealization.
Why do we minimize empirical risk instead of true risk if true risk is what we actually care about?
Because true risk requires integrating against , and is never available to us — we only ever observe samples drawn from it. Empirical risk is the only quantity computable from data alone, and by the law of large numbers it converges to the true risk for any fixed as the sample size grows. Minimizing it is therefore the natural, essentially forced, computational surrogate; the entire theoretical machinery of generalization bounds exists to quantify precisely how good this surrogate is, especially once itself is chosen based on the same data.
What's the difference between the loss function and the risk?
The loss function is a pointwise, deterministic measure of how bad one specific prediction is — it takes a true label and a predicted label and returns a single non-negative number. The risk is a single scalar summarizing the average loss of an entire function over the whole distribution of possible inputs and outputs: . In short, the loss evaluates one prediction; the risk evaluates an entire predictor's overall quality across every scenario it might encounter.
What exactly is the Bayes optimal predictor, and why does it matter?
For 0-1 loss, the Bayes optimal predictor is : at each input, predict whichever label is most probable given that input. It is provably the risk-minimizing function among all possible functions, not just those in some restricted hypothesis class, because minimizing the overall expected risk reduces to independently minimizing the conditional risk at each . It matters because its risk, the Bayes risk, is a hard floor: even with infinite data and unlimited model capacity, no classifier can do better, since remaining errors stem from genuine randomness in rather than from any deficiency of the learning algorithm.
How does the choice of loss function change what "optimal" means?
Different loss functions define different optimal predictors and, often, different optimal predicted quantities entirely. Squared loss is minimized in expectation by predicting the conditional mean , while absolute loss is minimized by the conditional median, and 0-1 loss is minimized by the conditional mode (most likely class). Choosing a loss function is therefore not a cosmetic detail — it is a substantive statement about which statistic of the conditional distribution you actually want your model to output, and mismatched loss choices can silently target the wrong quantity.
Does this framework apply outside supervised learning, e.g. to unsupervised or reinforcement learning?
The same skeleton generalizes, though the specifics change. In unsupervised learning there is no label ; instead one might define a risk over reconstruction loss (autoencoders) or a likelihood-based objective over an unknown distribution alone. In reinforcement learning, the analogous object is expected cumulative reward under an unknown environment dynamics and reward distribution, with a policy playing the role of the hypothesis. In every case, as introduced conceptually in Types of Learning: Supervised, Unsupervised, Reinforcement, the core tension persists: an unknown generative process, a proxy objective computable from finite interaction or data, and a gap between the two that theory must bound.
Why does this article stop short of discussing hypothesis space restrictions and generalization bounds?
Because those are logically separate concerns layered on top of the formal learning problem, not part of its basic statement. This article establishes what quantity we want to minimize (true risk) and what we can actually compute (empirical risk over a sample); it deliberately does not yet address which functions we are allowed to search over (the subject of Hypothesis Spaces) or how tightly empirical performance predicts true performance (the subject of Training Error vs Test Error). Separating these questions keeps each one precise and avoids conflating a definitional foundation with the theorems built on top of it.