Proba ML
5. Decision Theory
5.4 Empirical Risk Minimization

5.4 Empirical risk minimization

How to apply frequentist decision theory to supervised learning?

5.4.1 Empirical risk

In supervised learning, the true state of nature is the distribution p(x,y)p^*(x,y) and the estimator π\pi is a prediction function f(x)=y^f(x)=\hat{y}.

We define the population risk as:

R(f,p)=R(f)Ep(yx)p(x)[(f(x),y)]R(f,p^*)=R(f)\triangleq \mathbb{E}_{p^*(y|x)p^*(x)}[\ell(f(x),y)]

We can approximate pp^* using its empirical distribution:

pD(x,yD)=ptraining(x,yD)=1Dxn,ynDδ(xxn)δ(yyn)p_{\mathcal{D}}(x,y|\mathcal{D})=p_{training}(x,y|\mathcal{D})=\frac{1}{|\mathcal{D}|}\sum_{x_n,y_n \in \mathcal{D}} \delta(x-x_n)\delta(y-y_n)

Plugging this gives the empirical risk:

R(f,D)=EpD(x,y)[(f(xn),yn)]=1Nn=1N(f(xn),yn)R(f,\mathcal{D})=\mathbb{E}_{p_\mathcal{D}(x,y)}[\ell(f(x_n),y_n)]=\frac{1}{N}\sum_{n=1}^N\ell(f(x_n),y_n)

R(f,D)R(f,\mathcal{D}) is a random variable since it depends on the training set. We chose an estimator by minimizing the empirical risk over a specific hypothesis space of functions H\mathcal{H}:

f^ERM=arg minfHR(f,D)\hat{f}_{ERM}=\argmin_{f\in\mathcal{H}} R(f,D)

Approximation error vs generalization error

Let’s define:

  • f=arg minfR(f)f^{**}=\argmin_f R(f), the function that achieve the minimal possible population risk
  • f=arg minfHR(f)f^* =\argmin_{f\in\mathcal{H}}R(f) the best function of our hypothesis space H\mathcal{H}
  • fN=arg minfHR(f,D)=Eptr[(y,f(x))]f_{N}^*=\argmin_{f\in\mathcal{H}}R(f,\mathcal{D})=\mathbb{E}_{p_{tr}}[\ell(y,f(x))] the function that minimizes the empirical risk, since we can’t compute the population risk.

One can show that the risk of our chosen predictor can be compared to the best possible estimator with a two terms decomposition: the approximation error and the generalization error.

We can approximate this by the difference between the training and testing set errors:

Ep[R(fN)R(f)]=R(f)R(f)Eapp(H)+Ep[R(fN)R(f)]Eest(H,N)Eptr[(fN(x),y)]Epte[(fN(x),y)]\begin{align} \mathbb{E}_{p^*}[R(f^*_N)-R(f^{**})]&=\overbrace{R(f^*)-R(f^{**})}^{\mathcal{E}_{app}(\mathcal{H})} + \overbrace{\mathbb{E}_{p^*}[R(f^*_N)-R(f^*)]}^{\mathcal{E}_{est}(\mathcal{H,N})} \\ & \approx \mathbb{E_{p_{tr}}}[\ell(f^*_N(x), y)]-\mathbb{E_{p_{te}}}[\ell(f^*_N(x), y)] \end{align}

We can reduce the approximation error with a more complex model, but it may result in overfitting and increasing the generalization error.

Regularized risk

We add a complexity penalty C(f)C(f) to the objective function. Since we usually work with parametric functions, we apply the regularizer to the parameters θ\theta themselves:

Rλ(θ,D)=R(θ,D)+λC(θ)R_\lambda(\theta, \mathcal{D})=R(\theta, \mathcal{D})+\lambda C(\theta)

with λ>0\lambda >0 a hyperparameter.

If the risk is the log-loss and the penalty is the negative log prior, minimizing the empirical regularized risk is equivalent to estimating the MAP:

Rλ(θ,D)=1Nn=1Nlogp(ynxn,θ)λlogp(θ)R_\lambda(\theta,\mathcal{D})=-\frac{1}{N}\sum_{n=1}^N \log p(y_n|x_n,\theta)-\lambda \log p(\theta)

5.4.2 Structural risk

We estimate the hyperparameters with bilevel optimization:

λ^=arg minλminθRλ(θ,D)\hat{\lambda}=\argmin_\lambda \min_\theta R_\lambda(\theta,\mathcal{D})

However, this won’t work since this technique will always pick the least amount of regularization λ^=0\hat{\lambda}=0.

If we knew the population risk, we could minimize the structural risk and find the right complexity (the value of λ\lambda).

We can estimate the population risk via cross-validation or statistical learning.

5.4.3 Cross validation

Let Dtrain\mathcal{D}_{train} and Dval\mathcal{D}_{val} be two partitions of D\mathcal{D}, and:

θ^λ(D)=arg minθRλ(D,θ)\hat{\theta}_\lambda(\mathcal{D})=\argmin_\theta R_\lambda(\mathcal{D}, \theta)

For each model λ\lambda, we fit it to the training set to get θ^λ(Dtrain)\hat{\theta}_\lambda(\mathcal{D}_{train}).

We then use the unregularized risk on the validation set as an estimate of the population risk:

RλvalR0(θ^λ(Dtrain),Dval)R_\lambda^{val}\triangleq R_0(\hat{\theta}_\lambda(\mathcal{D}_{train}),\mathcal{D}_{val})

5.4.4 Statistical learning theory (SLT)

Cross validation is slow, so in SLT we derive analytically upper bound of the population risk (or more precisely the generalization error). If the bound is satisfied, we can be confident that minimizing the empirical risk will have low population risk.

For binary classifiers, we say the hypothesis is probably approximately correct (PAC), and the hypothesis class is PAC learnable.

Bounding the generalization error

Let use a finite of hypothesis space and dim(H)=H\dim(\mathcal{H)=|H|}. For any dataset D\mathcal{D} of size NN drawn from pp^*:

P(maxfHR(f)R(f,D)>ϵ)2dim(H)e2Nϵ2P(\max_{f\in\mathcal{H}}|R(f)-R(f,\mathcal{D})|>\epsilon)\leq 2\dim(\mathcal{H)}e^{-2N\epsilon^2}

where:

  • R(f,D)=1Ni=1NI(f(xi)yi)R(f,\mathcal{D})=\frac{1}{N}\sum_{i=1}^N \mathbb{I}(f(x_i)\neq y_i) is the population risk
  • R(f)=E[I(f(x)y)]R(f)=\mathbb{E}[\mathbb{I}(f(x)\neq y^*)] is the empirical risk

VC dimension

If the hypothesis space is infinite, we need to use an estimate of the degree of freedom of the hypothesis class. This is called VC dimension. Unfortunately this is hard to compute and the bounds are very loose.

However various estimates of the generalization error like the PAC-Bayesian bounds have recently been designed, especially for DNNs.