Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Empirical Risk Minimization: Foundations of Learning from Data

Welcome to the final lesson of our foundational module. In our previous session, we delved into Maximum Likelihood Estimation (MLE), establishing it as a powerful, principled method for fitting probabilistic models to data. We saw how it provides a theoretical justification for common techniques like least squares regression. Today, we will generalize this perspective to an even broader and more fundamental principle that underpins the majority of modern machine learning.

This lesson introduces Empirical Risk Minimization (ERM). You will learn to view machine learning not just as fitting a probabilistic model, but as a formal optimization problem aimed at minimizing prediction error. We will define the concepts of "true risk" and "empirical risk," explore the crucial trade-off between fitting our data and generalizing to new data, and see how MLE is simply a special case of this powerful ERM framework. This principle will serve as the theoretical bedrock for all the specific algorithms we will study in the upcoming modules.

The Ideal Goal: Minimizing True Risk

Imagine the ultimate goal of any learning system: to make the best possible predictions on any data it might encounter in the future, not just the data we used for training. To formalize this, we need two components: a way to measure error and a concept for "all possible data."

  1. Loss Function (): A function that quantifies the "cost" or "error" of making a prediction when the true value is . For example, the squared error, , is a common loss for regression tasks.
  2. True Data Distribution (): A hypothetical, unknown probability distribution from which all data points are drawn.

The ideal predictor, , would be one that minimizes the expected loss over this true distribution. We call this the expected risk or true risk.

Empirical Risk Minimization - Vincent Divol

This chapter from Vincent Divol's notes on mathematical tools for machine learning provides the formal definitions we need to begin.

Please read the first two pages, from the beginning up to the definition of the Bayes predictor. Focus on these parts: The setup for supervised learning and the i.i.d. assumption, which is central to this framework. The general concept of a loss function and its role. The definition of the P-risk, which is the formal name for the true risk. Finally, understand the definition of the Bayes predictor, which represents the theoretically optimal but practically unattainable solution that minimizes true risk.

The problem is clear: since we don't know the true data distribution , we cannot compute the true risk and therefore cannot find the Bayes predictor . This is where machine learning proposes a powerful approximation.

The Practical Approach: Minimizing Empirical Risk

If we can't calculate the expectation over the true distribution, the next best thing is to calculate the average over the data we do have. This is the central idea of Empirical Risk Minimization. We substitute the unknown true risk with the empirical risk: the average loss calculated over our finite training dataset.

The following video provides an excellent, intuitive explanation of this foundational idea.

Empirical Risk Minimization Explained | The Engine Behind Modern AI

This video, "Empirical Risk Minimization Explained," clearly articulates the shift from the ideal goal to the practical implementation.

Please watch the following segments: First, watch the section on the optimality criterion, which defines risk as the expected loss and highlights why it's not directly computable. Next, watch the core idea of ERM, which is to approximate the risk using the empirical mean over the training data. Finally, see how the Law of Large Numbers provides the probabilistic justification for this approximation. As our sample size grows, the empirical risk converges to the true risk.

So, the principle of ERM is to find the function that minimizes this empirical risk:

The Danger of Naive ERM and The Fundamental Trade-off

At first glance, this seems straightforward. However, a critical problem arises if we try to minimize the empirical risk over the space of all possible functions. It's almost always possible to find an absurdly complex function that perfectly "memorizes" the training data, achieving an empirical risk of zero. Such a function, however, would have learned the noise in our specific sample, not the underlying pattern, and would generalize terribly to new data. This is overfitting.

The solution is to constrain our search. We don't look for the best function among all possibilities; instead, we define a hypothesis space (also called a model) and search for the best function within that class. For example, could be the set of all linear functions, or all polynomials of degree 5.

This decision—choosing the complexity of our hypothesis space —introduces a fundamental trade-off. The performance of our learned model is governed by two competing error sources.

Empirical Risk Minimization - Vincent Divol

The same notes from Divol provide a clear, mathematical breakdown of this trade-off.

Please continue reading from "Section 2 Empirical risk" up to the end of the section on "Decomposition of the empirical risk". Focus on: The explanation of why simply minimizing empirical risk is flawed, and the introduction of minimizing it over a restricted class \mathcal{F}. The decomposition of the excess risk into two components. Understand the definitions: Approximation Error: This measures how well our chosen model \mathcal{F} can, in theory, approximate the true Bayes predictor. A simple model (like linear) might not be able to capture a complex true relationship, leading to high approximation error (underfitting). Estimation Error: This measures the penalty we pay for having a finite sample. It's the difference between the true risk of the function we found (\hat{f}_\mathcal{F}) and the best possible true risk within our model. A very complex model gives us too much freedom, so we might find a function that looks good on our sample but has high true risk, leading to high estimation error (overfitting).

This trade-off is at the very heart of statistical learning theory. As we increase the complexity of our hypothesis space :

  • The approximation error tends to decrease (a more complex model can better approximate the truth).
  • The estimation error tends to increase (a more complex model is more likely to overfit the limited data we have).

The goal of model selection is to find a hypothesis space that strikes the right balance between these two errors. The following graph is a classic illustration of this phenomenon.

This graph illustrates the relationship between true risk (\(R\)) and empirical risk (\(R_{emp}\)) as model complexity (the function class \(\mathcal{F}\)) increases. As the model becomes more complex, the empirical risk on the training data consistently decreases. However, the true risk on unseen data initially decreases (as the approximation error drops) but then starts to increase as the model begins to overfit the training data (estimation error dominates). The optimal model complexity is at the minimum of the true risk curve.

Unifying MLE and ERM

The ERM framework is powerful because it is so general. It applies to any choice of loss function and any hypothesis space . This generality allows it to encompass other learning principles, including the Maximum Likelihood Estimation we just studied.

The connection is direct and elegant: MLE is a special case of ERM where the loss function is the negative log-likelihood.

Let's see why. The MLE principle is to find the parameters that maximize the log-likelihood:

Maximizing a function is equivalent to minimizing its negative. Therefore, we can rewrite the MLE objective as:

If we define our loss function as , this is precisely the ERM objective.

Relating Bayesian Inference, Expected Risk Minimization and Maximum Likelihood Estimation

This article provides a concise summary of these connections.

Read the sections titled "ERM is the most widely used framework" and "Similarities." Pay special attention to the bullet point that explicitly states ERM reduces to MLE when the loss is chosen to be the negative log-likelihood.

This insight unifies the probabilistic view of MLE with the optimization view of ERM. When we minimize the sum of squared errors in linear regression, we are not only performing MLE under a Gaussian noise assumption (as seen in the last lesson), but we are also performing ERM with a squared-error loss function.

The flexibility of ERM allows us to choose loss functions that are not derived from a probabilistic model, tailoring them to the specific needs of a problem.

Machine Learning Lecture 16 "Empirical Risk Minimization" -Cornell CS4780 SP17

Professor Kilian Weinberger's lecture on ERM provides an excellent practical discussion of different loss functions and their properties.

Please watch the segment comparing two fundamental loss functions for regression: First, review the square loss. Note his explanation that minimizing this loss tends to make the model predict the mean of the target variable. This makes it sensitive to outliers. Next, watch the explanation of the absolute loss. In contrast, minimizing this loss leads to predicting the median, which is much more robust to outliers.

This ability to select a loss function based on desired properties, such as robustness to outliers, is a key strength of the ERM framework. Other advanced loss functions like the Huber loss (which he also discusses) are designed to get the best of both worlds.

Controlling Complexity with Regularization

We've established that controlling model complexity is essential to balance the approximation-estimation trade-off. While we can do this by explicitly choosing a simpler hypothesis space (e.g., linear models), a more common and powerful technique is regularization.

Regularization involves adding a penalty term, , to the empirical risk objective. This term penalizes model complexity. The new objective becomes:

The hyperparameter controls the strength of the regularization, allowing us to tune the trade-off. A larger pushes the model towards simpler solutions.

A particularly insightful way to understand regularization is to see its equivalence to a constrained optimization problem.

Machine Learning Lecture 16 "Empirical Risk Minimization" -Cornell CS4780 SP17

Let's return to the same lecture for a brilliant explanation of regularization.

Please watch the final segment on regularization. First, watch his introduction to regularization as an additional term in the objective. Then, pay close attention to the theoretical equivalence between adding a penalty term and solving a constrained optimization problem. His visualization of the solution being forced to lie within a "ball" defined by the regularizer is a powerful mental model that you will find useful throughout your study of ML.

This constrained view makes the purpose of regularization explicit: we are searching for the best solution not in the entire hypothesis space, but within a smaller, constrained region of "simpler" functions. This directly combats overfitting by limiting the model's capacity.

Conclusion

This lesson has introduced Empirical Risk Minimization, the theoretical engine driving much of modern machine learning. It provides a formal language for thinking about learning as an optimization problem.

Here are the key takeaways:

  • ERM Principle: Since we cannot compute the true risk (expected loss over all possible data), we minimize the empirical risk (average loss over our training data) as a proxy.
  • The Fundamental Trade-off: The choice of model complexity (the hypothesis space) involves a trade-off between approximation error (how well the model can fit the true signal) and estimation error (how much the model overfits the finite sample). This manifests as the tension between underfitting and overfitting.
  • ERM as a Unifying Framework: ERM is a general principle. Maximum Likelihood Estimation is a special case of ERM where the loss function is the negative log-likelihood.
  • Controlling Complexity: We must restrict model complexity to achieve good generalization. Regularization is the primary mechanism for this, adding a penalty for complexity to the ERM objective.

With this lesson, we conclude our tour of the essential mathematical and statistical foundations. You are now equipped with the core theoretical principles—probability, optimization, MLE, and ERM—that underpin machine learning.

In the next module, "Core Concepts of Supervised Learning," we will leave the realm of pure theory and begin applying these principles to construct and analyze our first concrete machine learning models. We will start by defining the field of machine learning more formally and building our first algorithm, linear regression, directly from the ERM principle.

Can't find a good explanation? Sign up and we'll make it for you

Sign up