As a hitchhiker in learning theory, I constantly bump into a weird kind of problems, where an overfitted hypothesis still predicts certain population quantities accurately. One specific instance is about the 2nd moment of prediction which will be today’s topic.1 After being haunted by the issue for years,2 I finally figured out a way to nicely characterize the phenomenon.


Problem Setup

Consider a standard least-square regression problem where we have i.i.d. sample X1:n,Y1:nX_{1:n}, Y_{1:n}. Let f^\hat{f} be ERM from function class F\mathcal{F}, i.e.,

f^argminfFLn(f):=En[(f(X)Y)2],\hat{f} \in \arg\min_{f\in\mathcal{F}} L_n(f) := \mathbb{E}_n[(f(X)-Y)^2],

where En\mathbb{E}_n denotes empirical expectation. Let’s assume realizability, i.e., fFf^\star \in \mathcal{F} where f(X)=E[YX]f^\star(X) = \mathbb{E}[Y\mid X] is the Bayes-optimal predictor. All fFf \in \mathcal{F} and YY are bounded in [0,1][0, 1]. The quantity of interest is

En[f^2].\mathbb{E}_n[\hat{f}^2].

The goal is to show that En[f^2]\mathbb{E}_n[\hat{f}^2] is bounded by something not large. (As we will see, this something may not be fixed!)


Standard Approach

The standard approach is to show that En[f^2]E[(f)2]\mathbb{E}_n[\hat{f}^2] \approx \mathbb{E}[(f^\star)^2] since f^f\hat f \to f^\star with enough data. To ensure this, we need to pay comp(F)\textup{comp}(\mathcal{F}), the complexity of the function class (e.g., logF\log \vert \mathcal{F} \vert for finite classes, or dimensionality dd for linear): with high probability,

E[(f^f)2]comp(F)n.\mathbb{E}[(\hat{f} - f^\star)^2] \lesssim \frac{\textup{comp}(\mathcal{F})}{n}.

Define n2=En[()2]\|\cdot\|_n^2 = \mathbb{E}_n[(\cdot)^2], then En[f^2]=f^n2\mathbb{E}_n[\hat{f}^2] = \|\hat{f}\|_n^2, and

f^nfn+f^fn.\|\hat{f}\|_n \le \|f^\star\|_n + \|\hat{f} - f^\star\|_n.

The second term is controlled by comp(F)/n\sqrt{\textup{comp}(\mathcal{F})/n}. For the first term, we can use standard concentration to relate E[(f)2]\mathbb{E}[(f^\star)^2] to En[(f)2]\mathbb{E}_n[(f^\star)^2] and this term does not involve comp(F)\textup{comp}(\mathcal{F}) since it’s w.r.t. a fixed function ff^\star. As nn increases, the upper bound converges to E[(f)2]\mathbb{E}[(f^\star)^2].


The Overfitting Regime

The problem with the above bound is that when F\mathcal{F} is extremely expressive, the bound can grow indefinitely with comp(F)\textup{comp}(\mathcal{F}) all the way to infinity. However, if we completely overfit, then we’d have f^(Xi)=Yi\hat{f}(X_i) = Y_i, and

En[f^2]=En[Y2],\mathbb{E}_n[\hat{f}^2] = \mathbb{E}_n[Y^2],

which clearly concentrates towards E[Y2]\mathbb{E}[Y^2] in a comp(F)\textup{comp}(\mathcal{F})-free manner! Believe or not, I have run into a number of scenarios like this, where an upper bound close to E[Y2]\mathbb{E}[Y^2] is totally acceptable.3 (NB: this is a different target compared to the previous analysis where the upper bound is close to E[(f)2]\mathbb{E}[(f^\star)^2].) What I’d really love to have is a single bound that covers both cases: in the good-fit regime (comp(F)\textup{comp}(\mathcal{F}) small), the bound should be close to E[(f)2]\mathbb{E}[(f^\star)^2]); in the over-fit regime (comp(F)\textup{comp}(\mathcal{F}) large), the bound is close to E[Y2]\mathbb{E}[Y^2]). Better still, perhaps the bound can even provide characterization for the continuous spectrum in between.


Unified Analysis through Empirical Pythagoreans

I gave this weird problem some thought every time I ran into it, but always gave up due to its messiness and lack of urgency. Thanks to LLMs, I was able to dig into it deeply recently and figured out a solution. The key is the empirical Pythagoreans that4

En[Y2]=En[f^2]+En[(Yf^)2],\mathbb{E}_n[Y^2] = \mathbb{E}_n[\hat{f}^2] + \mathbb{E}_n[(Y - \hat{f})^2],

which holds as long as F\mathcal{F} is closed under scaling, i.e., afF,fFa f \in \mathcal{F}, \forall f\in\mathcal{F} for constant scalar aa. To see why this is true, note that the identity will generally be violated by a cross-term

2En[(Yf^)f^].2\mathbb{E}_n[(Y - \hat{f})\hat{f}].

On the other hand, given f^\hat{f} is ERM, we can consider the derivative of the empirical loss Ln()L_n(\cdot) along the direction of af^a \hat{f}, which should be 00 at a=1a=1:

0=En[(Yaf^)2]aa=1=2En[(Yaf^)f^]a=1=2En[(Yf^)f^],0 = \frac{\partial \mathbb{E}_n[(Y - a\hat{f})^2]}{\partial a} \Big\vert_{a=1} = 2 \mathbb{E}_n[(Y - a \hat{f}) \hat{f}] \big\vert_{a=1} = 2\mathbb{E}_n[(Y - \hat{f})\hat{f}],

which establishes the empirical Pythagoreans. Then

En[f^2]=En[Y2]En[(Yf^)2].(1)\mathbb{E}_n[\hat{f}^2] = \mathbb{E}_n[Y^2] - \mathbb{E}_n[(Y - \hat{f})^2]. \qquad (1)

For the first term, En[Y2]\mathbb{E}_n[Y^2] concentrates to E[Y2]\mathbb{E}[Y^2] and this clearly does not involve F\mathcal{F}; in fact, we need to pay this anyway even in the perfect overfitting case (f^(Xi)=Yi\hat{f}(X_i) = Y_i). The second term is the empirical loss of f^\hat{f}, Ln(f^)L_n(\hat{f}); let L()L(\cdot) be the population loss. Therefore, to obtain an upper bound on En[f^2]\mathbb{E}_n[\hat{f}^2], we need a lower bound on Ln(f^)L_n(\hat{f}). One trivial (but later useful) lower bound is 00. Another comes from bounding

Ln(f^)L(f)Ln(f^)L(f^)+L(f^)L(f)comp(F)/n,\lvert L_n(\hat{f}) - L(f^\star)\rvert \le \lvert L_n(\hat{f}) - L(\hat{f})\rvert + \lvert L(\hat{f}) - L(f^\star) \rvert \lesssim \sqrt{\textup{comp}(\mathcal{F})/n},

as the first term is bounded by concentration + union bound, and the second can be similarly bounded by introducing Ln(f^)+Ln(f)- L_n(\hat{f}) + L_n(f^\star). Therefore, the second lower bound of Ln(f^)L_n(\hat{f}) is

Ln(f^)L(f)O(comp(F)/n).L_n(\hat{f}) \ge L(f^\star) - O(\sqrt{\textup{comp}(\mathcal{F})/n}).

Put together into Eq.(1), we have

En[f^2]E[Y2]max{0,L(f)O(comp(F)/n)}+O(1/n).\mathbb{E}_n[\hat{f}^2] \le \mathbb{E}[Y^2] - \max\left\{0, L(f^\star) - O(\sqrt{\textup{comp}(\mathcal{F})/n})\right\} + O(1/\sqrt{n}).

This perfectly captures both the good-fit and over-fit regimes: when comp(F)\textup{comp}(\mathcal{F}) is very large, the 00 is active inside max\max and we have an upper bound close to E[Y2]\mathbb{E}[Y^2]; when comp(F)\textup{comp}(\mathcal{F}) is small, L(f)L(f^\star) becomes active; when combined with E[Y2]\mathbb{E}[Y^2], this recovers

E[Y2]L(f)=E[(f)2].\mathbb{E}[Y^2] - L(f^\star) = \mathbb{E}[(f^\star)^2].

As conclusion, the “max{0,}\max\{0, \ldots\}” is not as elegant as I hoped, but given the numerous failures I am pretty satisfied with the current form. Also it does provide characterization for the intermediate regime where comp(F)/n\sqrt{\textup{comp}(\mathcal{F})/n} gradually decreases below L(f)L(f^\star). Finally, I believe the analysis also holds in the misspecified case where we replace ff^\star with the population best fit (which may not be unique), as long as we have closure under rescaling and E[f(Yf)]=0\mathbb{E}[f^\star(Y - f^\star)]=0. This enables the population version of Pythagoreans for ff^\star which is the only property we need.


Footnote Remarks

  1. A simpler example is when we predict E[Y]En[f^]\mathbb{E}[Y] \approx \mathbb{E}_n[\hat{f}], which is always accurate provided that F\mathcal{F} is closed under offset, as that implies En[f^]=En[Y]\mathbb{E}_n[\hat{f}] = \mathbb{E}_n[Y]

  2. Some years ago when Alekh, Sham, and I discussed RL at MSR (that was before we started working on the book), Sham once made a point along the lines of: if you fit TD from on-policy trajectories, and you totally overfit, then it just recovers Monte-Carlo? which is very much along the spirit of this post. And guess what, we are working on something related (and very exciting!) and that’s what got me into this rabbit hole again… 

  3. An example is Proposition 3 here. Generally this result might be useful when you care about the loss rather than the minimizer (i.e., min vs. argmin). 

  4. In fact we could stop here, as it shows that En[f^2]En[Y2]\mathbb{E}_n[\hat f^2] \le \mathbb{E}_n[Y^2]. We can just combine this with the previous comp(F)\textup{comp}(\mathcal{F})-based bound and take the minimum over the two. I think technically this is not much different from what I am doing in the main text, but retrospectively this alternative approach feels conceptually more straightforward…?