4.3 Hoeffding’s inequality

One tool to understand the connection between the in-sample and out-of-sample error is Hoeffding’s inequality. This is a result from probability theory and so we will present it as such. That is, in this section we do not discuss any application to statistical learning. It is not formally part of the course, but for the interested, it gives some theoretical understanding of the relation between the in-sample error and out-of-sample error.

Hoeffding’s inequality states that: Let \(Y_1,\ldots, Y_n\) be iid with \(E[Y_i]=\mu\) and \(a\leq Y_i \leq b\). Then for any \(\varepsilon>0\), \[ P\left( \left| \bar Y_n - \mu \right|>\varepsilon \right) \leq 2e^{-2n\varepsilon^2/(b-a)^2}. \]

The inequality is true for any random variable satisfying the conditions. However, we will only prove the special case that if \(Y_i\overset{iid}{\sim}\mathsf{Be}(p)\), then \[ P\left( \left| \bar Y_n - p \right|>\varepsilon \right) \leq 2e^{-2n\varepsilon^2}. \] We start by deriving Markov’s inequality: Let \(X\) be a non-negative random variable. For the sake of this calculation we assume \(X\) is continuous with density \(p(x)\), although the inequality holds also when this is not the case. Then for any \(t>0\), \[\begin{align} E[X] &= \int_0^\infty xp(x)dx = \int_0^t xp(x)dx + \int_t^\infty xp(x)dx \\ &\geq \int_t^\infty x p(x)dx \geq t \int_t^\infty p(x)dx = tP(X> t). \end{align}\] We usually write this as \(P(X>t)\leq E(X)/t\).

Now we turn to Hoeffding’s inequality. Firstly, \[ P\left( \left| \bar Y_n - p \right|\geq \varepsilon \right) = P\left( \bar Y_n \geq p+\varepsilon \right) + P\left( \bar Y_n \leq p - \varepsilon \right). \] Then we use that \(\exp\) is an increasing function, together with Markov’s inequality, for any \(t>0\), \[\begin{align*} P\left( \bar Y_n \geq p + \varepsilon \right) &= P\left( t\sum_{i=1}^n Y_i \geq tn(p + \varepsilon) \right) = P\left( e^{t\sum_{i=1}^n Y_i }\geq e^{tn(p +\varepsilon) } \right) \\ &\overset{\text{Markov}}{\leq} e^{-tn(p+\varepsilon)}E\left[ e^{t\sum_{i=1}^n Y_i } \right] \overset{indep.}{=} e^{-tn(p+\varepsilon)}\prod_{n=1}^nE\left[ e^{t Y_i } \right] = e^{-tn(p+\varepsilon)}E\left[ e^{t Y_i } \right]^n. \end{align*}\]

Now we need to bound the last expression. Since \(Y_i\) is Bernoulli, \[ E\left[ e^{t Y_i } \right] = e^{t\cdot 1}P(Y_i=1) + e^{t\cdot 0}P(Y_i=0) = pe^t + (1-p). \] We would like to show that \(pe^t+1-p\leq e^{tp+t^2/8}\). Since then, \[ P\left( \bar Y_n \geq p + \varepsilon \right) \leq e^{-tn(p+\varepsilon)}E\left[ e^{t Y_i } \right]^n \leq e^{-tn(p+\varepsilon)} e^{ntp+nt^2/8} = e^{-nt\varepsilon + nt^2/8} \leq e^{-2n\varepsilon^2}, \] which is what we want. In the last step we used that \(-nt\varepsilon + nt^2/8\) has a maximum at \(t=4\varepsilon\), which is easy to check. A similar argument will give that \(P\left( \bar Y_n \leq p - \varepsilon \right)\) can be bounded in the same way and then we arrive at Hoeffding’s inequality.

So, we need to study \(pe^t+1-p\) and \(e^{tp+t^2/8}\). First note that the inequality is true if and only if \[ f(t):=\ln (pe^t+1-p) \leq tp+t^2/8, \] since \(\ln\) is increasing. By Taylor’s theorem, we can write \[ f(t) = f(0) + f'(0)t + f''(\zeta)\frac{t^2}{2}, \] for some \(0\leq \zeta \leq t.\) However \(f(0)=0\) and \(f'(0) = \frac{pe^0}{pe^0+1-p} = p\) and \[ f''(t) = \frac{pe^t}{pe^t+1-p} - \frac{(pe^t)^2}{(pe^t+1-p)^2} = \frac{pe^t}{pe^t+1-p}\left( 1-\frac{pe^t}{pe^t+1-p} \right) = \rho(1-\rho), \] with \(\rho:= \frac{pe^t}{pe^t+1-p}.\) Now, it is easy to see that \(0\leq\rho\leq 1\) therefore that \(\rho(1-\rho)\leq 1/4\) so that \(f''(t)\leq 1/4.\) All together, \[ f(t) = tp + f''(\zeta)\frac{t^2}{2} \leq tp + \frac{t^2}{8}, \] and we are done.

If we choose \[ \varepsilon = \sqrt{\frac{1}{2n}\ln \frac{2}{\delta}}, \] we get \[ P\left( \left| \bar Y_n - p \right|\leq \sqrt{\frac{1}{2n}\ln \frac{2}{\delta}} \right) \geq 1-2\exp\left( -2n\frac{1}{2n}\ln \frac{2}{\delta} \right) =1-\delta. \]
Stated another way, with probability at least \(1-\delta\), \[ \left| \bar Y_n - p \right|\leq \sqrt{\frac{1}{2n}\ln \frac{2}{\delta}}. \]