MIT 6.790 — Lecture 2

ERM and MLE

Let's still assume all data is drawn (i.i.d.) from some fixed distribution pp, but say we don't know what pp is.

Remark. This isn't entirely realistic—sensor data, say, might have temporal correlations.

§ Empirical Risk Minimization

Here's a very simple idea: Use our training data {(x(n),y(n))}n=1N\{(x^{(n)}, y^{(n)})\}_{n = 1}^N to derive an empirical distribution like so:

p^(x,y):=1Nn=1Nδ(x(n),y(n))(x,y).\widehat{p}(x, y) := \frac{1}{N} \sum_{n = 1}^N \delta_{(x^{(n)}, y^{(n)})}(x, y).

Here, δk(x)\delta_k(x) is the Dirac delta function, defined so that RDδk(x)dx=1\int_{\mathbb{R}^D} \delta_k(x) \, \mathrm{d}x = 1 and δk(x)=0\delta_k(x) = 0 for all xkx \neq k.

Using the empirical distribution also gives us an empirical risk that looks like:

risk^(h)=1Nn=1NL(y(n),h(x(n))).\widehat{\text{risk}}(h) = \frac{1}{N} \sum_{n = 1}^N L(y^{(n)}, h(x^{(n)})).

And so we might choose hh according to Empirical Risk Minimization (ERM), like so:

hErm=arg minhHrisk^(h),h_{\textsc{Erm}} = \argmin_{h \in \mathcal{H}} \widehat{\text{risk}}(h),

where H\mathcal{H} is some class of candidate decision rules.

§ Overfitting

Of course, this stupid solution fails in stupid ways.

Example. Given a training set of spam / not-spam emails, decide whether future emails are spam.

ERM Solution. An email is declared spam if its timestamp matches that of a spam email in the training set.

This is an example of overfitting. Here are two approaches by which we might fix it:

  1. Restrict the hypothesis class H\mathcal{H}.

  2. Approximate p(x,y)p(x, y) differently.

Let's take the latter of the two approaches for now: how can we better estimate p(x,y)p(x, y)?

§ Maximum Likelihood Estimation

Remark. This section is written with the assumption of 18.650, particularly up through Lecture 9, which covers the MLE.

Rather than naively approximating p(x,y)p(x, y) using the empirical distribution p^(x,y)\widehat{p}(x, y), let's suppose pp belongs to a parametric model and estimate the parameter of pp via the MLE.

Example. (Bernoulli MLE) Suppose, for simplicity, that we only care about approximating the distribution of labels {y(n)}n=1N\{y^{(n)}\}_{n = 1}^N and ignore the features {x(n)}n=1N\{x^{(n)}\}_{n = 1}^N. Also assume that the y(n){0,1}y^{(n)} \in \{0, 1\} are sampled from Ber(θ)\mathrm{Ber}(\theta) for some θ[0,1]\theta \in [0, 1].

As a function of the samples {y(n)}n=1N\{y^{(n)}\}_{n = 1}^N, determine the MLE θ^\hat{\theta}.

Solution: Because the labels {y(n)}n=1N\{y^{(n)}\}_{n = 1}^N are independent, the likelihood is:

p(Dθ)=n=1Np(y(n)θ)=n=1Nθy(n)(1θ)1y(n).p(\mathcal{D} \mid \theta) = \prod_{n = 1}^N p(y^{(n)} \mid \theta) = \prod_{n = 1}^N \theta^{y^{(n)}} (1 - \theta)^{1 - y^{(n)}}.

We'd like to maximize the above, so it is natural to differentiate the above with respect to θ\theta… but the result seems very messy. The trick, of course, is to consider the log-likelihood:

(θ)=logp(Dθ)=n=1N[y(n)logθ+(1y(n))log(1θ)].\ell(\theta) = \log p(\mathcal{D} \mid \theta) = \sum_{n = 1}^N \left[ y^{(n)} \log \theta + (1 - y^{(n)}) \log (1 - \theta) \right].

Technically we should treat θ{0,1}\theta \in \{0, 1\} separately. That aside, we can now differentiate (θ)\ell(\theta) easily.

ddθ(θ)=1θ[n=1Ny(n)]11θ[n=1N(1y(n))].\frac{d}{d\theta} \ell(\theta) = \frac{1}{\theta}\left[\sum_{n = 1}^N y^{(n)}\right] - \frac{1}{1 - \theta}\left[\sum_{n = 1}^N (1 - y^{(n)})\right].

The above equals 00 exactly at θ^=1Nn=1Ny(n)\hat{\theta} = \frac{1}{N}\sum_{n = 1}^N y^{(n)}. It now remains to check that this critical point is a maximum:

d2dθ2(θ)=1θ2[n=1Ny(n)]1(1θ)2[n=1N(1y(n))]<0.\frac{d^2}{d\theta^2} \ell(\theta) = -\frac{1}{\theta^2}\left[\sum_{n = 1}^N y^{(n)}\right] - \frac{1}{(1 - \theta)^2}\left[\sum_{n = 1}^N (1 - y^{(n)})\right] < 0.

So the MLE must be θ^=1Nn=1Ny(n)\hat{\theta} = \frac{1}{N}\sum_{n = 1}^N y^{(n)}.   \blacksquare

§ MLE Advantages and Disadvantages

The MLE has some advantages!

But it also has some disadvantages.