{"word_count": 1513, "character_count": 13612}
This post is the nineth (and probably last) one of our series on the history and foundations of econometric and machine learning models. The first fours were on econometrics techniques. Part 8 is online here.Optimization and algorithmic aspectsIn econometrics, (numerical) optimization became omnipresent as soon as we left the Gaussian model. We briefly mentioned it in the section on the exponential family, and the use of the Fisher score (gradient descent) to solve the first order condition [latex]\mathbf{X}^T W(\beta)^{-1})[y-\widehat{y}]=\mathbf{0}[/latex]. In learning, optimization is the central tool. And it is necessary to have effective optimization algorithms, to solve problems (described previously) of the form: [latex display="true"]\widehat{\beta}\in\underset{\beta\in\mathbb{R}^p}{\text{argmin}}\left\lbrace\sum_{i=1}^n \ell(y_i,\beta_0+\mathbf{x}^T\beta)+\lambda\Vert\boldsymbol{\beta}\Vert\right\rbrace[/latex]In some cases, instead of global optimization, it is sufficient to consider optimization by coordinates (widely studied in Daubechies et al. (2004)). If [latex]f:\mathbb{R}^d\rightarrow\mathbf{R}[/latex] is convex and differentiable, if [latex]\mathbf{x}[/latex] satisfies [latex]f(\mathbf{x}+h\boldsymbol{e}_i)\geq f(\mathbf{x})[/latex] for any [latex]h&#62;0[/latex] and [latex]i\in\{1,\cdots, d\}[/latex]then [latex] f(\mathbf{x})=\min\{f\}[/latex], where [latex]\mathbf{e}=(\mathbf{e}_i)[/latex] is the canonical basis of [latex]\mathbb{R}^d[/latex]. However, this property is not true in the non-differentiable case. But if we assume that the non-differentiable part is separable (additively), it becomes true again. More specifically, if[latex display="true"]f(\mathbf{x})=g(\mathbf{x})+\sum_{i=1}^d h_i(x_i)[/latex]with[latex display="true"]\left\lbrace\begin{array}{l}g: \mathbb{R}^d\rightarrow\mathbb{R}\text{ convex-differentiable}\\h_i: \mathbb{R}\rightarrow\mathbb{R}\text{ convex}\end{array}\right.[/latex]This was the case for Lasso regression, [latex]\beta)\mapsto\| \mathbf{y}-\beta_0-\mathbf{X}\beta\|_{\ell_2 }+\lambda\|\beta\|_{\ell_1}[/latex], as shown by Tsen (2001). Getting back to our initial notations, we can use a coordinate descent algorithm: from an initial value [latex]\mathbf{x}^{(0)}[/latex], we consider (by iterating)[latex display="true"]x_j^{(k)}\in\text{argmin}\big\lbrace f(x_1^{(k)},\cdots,x_{k-1}^{(k)},x_k,x_{k+1}^{(k-1)},\cdots,x_n^{(k-1)})\big\rbrace [/latex] for [latex]j=1,2,\cdots,n[/latex]These algorithmic problems and numerical issues may seem secondary to econometricians. However, they are essential in automatic learning: a technique is interesting if there is a stable and fast algorithm, which allows to obtain a solution. These optimization techniques can be transposed: for example, this coordinate descent technique can be used in the case of SVM methods (known as "vector support" methods) when the space is not linearly separable, and the classification error must be penalized (we will come back to this technique in the next section).In-sample, out-of-sample and cross-validationThese techniques seem intellectually interesting, but we have not yet discussed the choice of the penalty parameter [latex]\lambda[/latex]. But this problem is actually more general, because comparing two parameters [latex]\widehat{\beta}_{\lambda_1}[/latex] and [latex]\widehat{\beta}_{\lambda_2}[/latex] is actually comparing two models. In particular, if we use a Lasso method, with different thresholds [latex]\lambda[/latex], we compare models that do not have the same dimension. Previously, we have addressed the problem of model comparison from an econometric perspective (by penalizing overly complex models). In the learning literature, judging the quality of a model on the data used to construct it does not make it possible to know how the model will behave on new data. This is the so-called "generalization" problem. The traditional approach then consists in separating the sample (size [latex]n[/latex]) into two parts: a part that will be used to train the model (the training database, in-sample, size [latex]m[/latex]) and a part that will be used to test the model (the testing database, out-of-sample, size [latex]n-m[/latex]). The latter then makes it possible to measure a real predictive risk. Suppose that the data are generated by a linear model [latex]y_i=\mathbf{x}_i^T \beta_0+\varepsilon_i[/latex] where [latex]\varepsilon_i[/latex] are independent and centred law achievements. The empirical quadratic risk in-sample is here[latex display="true"]\frac{1}{m}\sum_{i=1}^m\mathbb{E}\big([\mathbf{x}_i^T \widehat{\beta}-\mathbf{x}_i^T \beta_0]^2\big)=\mathbb{E}\big([\mathbf{x}_i^T \widehat{\beta}-\mathbf{x}_i^T \beta_0]^2\big),[/latex]for any observation [latex]i[/latex]. Assuming the residuals [latex]\varepsilon[/latex] Gaussian, then we can show that this risk is worth [latex]\sigma^2 \text{trace} (\Pi_X)/m[/latex] is [latex]\sigma^2 p/m[/latex]. On the other hand, the empirical out-of-sample quadratic risk is here [latex display="true"]\mathbb{E}\big([\mathbf{x}^T \widehat{\beta}-\mathbf{x}^T \beta_0]^2\big) [/latex]where [latex]\mathbf{x}[/latex] is a new observation, independent of the others. It can be noted that [latex display="true"]\mathbb{E}\big([\mathbf{x}^T \widehat{\beta}-\mathbf{x}^T \beta_0]^2\big\vert \mathbf{x}\big)=\text{Var}\big(\mathbf{x}^T \widehat{\beta}\big\vert \mathbf{x}\big)=\sigma^2\mathbf{x}^T(\mathbf{x}^T\mathbf{x})^{-1}\mathbf{x},[/latex]and by integrating with respect to [latex]\mathbf{x}[/latex], [latex display="true"]\mathbb{E}\big([\mathbf{x}^T \widehat{\beta}-\mathbf{x}^T\beta_0]^2\big)=\sigma^2\text{trace}\big(\mathbb{E}[\mathbf{x}\mathbf{x}^T]\mathbb{E}\big[(\mathbf{x}^T\mathbf{x})^{-1}\big]\big).[/latex]The expression is then different from that obtained in-sample, and using the Groves &#38; Rothenberg (1969) increase, we can show that [latex display="true"]\mathbb{E}\big([\mathbf{x}^T \widehat{\beta}-\mathbf{x}^T \beta_0]^2\big) \geq \sigma^2\frac{p}{m}[/latex]which is pretty intuitive, when we start thinking about it. Except in some simple cases, there is no simple (explicit) formula. Note, however, that if [latex]\mathbf{X}\sim\mathcal{N}(0,\sigma^2 \mathbb{I})[/latex], then [latex]\mathbf{x}^T \mathbf{x}[/latex] follows a Wishart law, and it can be shown that [latex display="true"]\mathbb{E}\big([\mathbf{x}^T \widehat{\beta}-\mathbf{x}^T \beta_0]^2\big)=\sigma^2\frac{p}{m-p-1}.[/latex]If we now look at the empirical version: if [latex]\widehat{\beta}[/latex] is estimated on the first [latex]m[/latex] observations,[latex display="true"]\widehat{\mathcal{R}}^{~\text{ IS}}=\sum_{i=1}^m [y_i-\boldsymbol{x}_i^T\widehat{\boldsymbol{\beta}}]^2\text{ and }\widehat{\mathcal{R}}^{\text{ OS}}=\sum_{i=m+1}^{n} [y_i-\boldsymbol{x}_i^T\widehat{\boldsymbol{\beta}}]^2[/latex]and as Leeb (2008) noted, [latex] \widehat{\mathcal{R}}^{\text{IS}}-\widehat{\mathcal{R}}^{\text{OS}}\approx 2\cdot\nu[/latex] where [latex]\nu[/latex] represents the number of degrees of freedom, which is not unlike the penalty used in the Akaike test.Figure 4 shows the respective evolution of [latex] \widehat{\mathcal{R}}^{\text{IS}} [/latex] and [latex] \widehat{\mathcal{R}}^{\text{OS}}[/latex] according to the complexity of the model (number of degrees in a polynomial regression, number of nodes in splines, etc). The more complex the model, the more [latex] \widehat{\mathcal{R}}^{\text{IS}}[/latex] will decrease (this is the red curve, below). But that's not what we're interested in here: we want a model that predicts well on new data (i. e. out-of-sample). As Figure 4 shows, if the model is too simple, it does not predict well (as it does with in-sample data). But what we can see is that if the model is too complex, we are in a situation of "overlearning": the model will start to model the noise. Of course, this figure should remind us of the one we've seen in our second post of that seriesFigure 4 : Generalization, under- and over-fittingInstead of splitting the database in two, with some of the data that will be used to calibrate the model and some to study its performance, it is also possible to use cross-validation. To present the general idea, we can go back to the "jackknife", introduced by Quenouille (1949) (and formalized by Quenouille (1956) and Tukey (1958)) relatively used in statistics to reduce bias. Indeed, if we assume that [latex]\{y_1,\cdots,y_n\}[/latex] is a sample drawn according to a law [latex]F_\theta[/latex], and that we have an estimator [latex]T_n (\mathbf{y})=T_n (y_1,\cdots,y_n)[/latex], but that this estimator is biased, with [latex]\mathbf{E}[T_n (\mathbf{Y})]=\theta+O(n^{-1})[/latex], it is possible to reduce the bias by considering [latex display="true"]\widetilde{T}_n(\mathbf{y})=\frac{1}{n}\sum_{i=1}^n T_{n-1}(\mathbf{y}_{(i)})\text{ where }\mathbf{y}_{(i)}=(y_1,\cdots,y_{i-1},y_{i+1},\cdots,y_n)[/latex]It can then be shown that [latex]\mathbb{E}[\tilde{T}_n(Y)]=\theta+O(n^{-2})[/latex]The idea of cross-validation is based on the idea of building an estimator by removing an observation. Since we want to build a predictive model, we will compare the forecast obtained with the estimated model, and the missing observation[latex display="true"]\widehat{\mathcal{R}}^{\text{ CV}}=\frac{1}{n}\sum_{i=1}^n \ell(y_i,\widehat{m}_{(i)}(\mathbf{x}_i))[/latex]We will speak here of the "leave-one-out" (loocv) method.This technique reminds us of the traditional method used to find the optimal parameter in exponential smoothing methods for time series. In simple smoothing, we will construct a forecast from a time series as [latex]{}_t\widehat{y}_{t+1} =\alpha\cdot{}_{t-1}\widehat{y}_t +(1-\alpha)\cdot y_t[/latex], where [latex]\alpha\in[0,1][/latex], and we will consider as “optimal” [latex display="true"]\alpha^\star = \underset{\alpha\in[0,1]}{\text{argmin}}\left\lbrace \sum_{t=2}^T \ell({}_{t-1}\widehat{y}_{t},y_{t}) \right\rbrace[/latex]as described by Hyndman et al (2009).The main problem with the leave-one-out method is that it requires calibration of n models, which can be problematic in large dimensions. An alternative method is cross validation by [latex]k[/latex]-blocks (called "[latex]k[/latex]-fold cross validation") which consists in using a partition of [latex]\{1,\cdots,n\}[/latex] in [latex]k[/latex] groups (or blocks) of the same size, [latex]\mathcal{I}_1,\cdots,\mathcal{I}_k[/latex], and let us note [latex]\mathcal{I}_{\bar j}=\{1,\cdots,n\}\setminus \mathcal{I}_j[/latex]. By noting [latex]\widehat{m}_{(j)}[/latex] built on the sample [latex]\mathcal{I}_{\bar j}[/latex], we then set:[latex display="true"]\widehat{\mathcal{R}}^{k-\text{ CV}}=\frac{1}{k}\sum_{j=1}^k \mathcal{R}_j\text{ where }\mathcal{R}_j=\frac{k}{n}\sum_{i\in\mathcal{I}_{{j}}} \ell(y_i,\widehat{m}_{(j)}(\mathbf{x}_i))[/latex]Standard cross-validation, where only one observation is removed each time (loocv), is a special case, with [latex]k=n[/latex]. Using [latex]k=5[/latex] or [latex]10[/latex] has a double advantage over [latex]k=n[/latex]: (1) the number of estimates to be made is much smaller, 5 or 10 rather than [latex]n[/latex]; (2) the samples used for estimation are less similar and therefore less correlated to each other, which tends to avoid excess variance, as recalled by James et al. (2013).Another alternative is to use boosted samples. Let [latex]\mathcal{I}_b[/latex] be a sample of size [latex]n[/latex] obtained by drawing with replacement in [latex]\{1,\cdots,n\}[/latex] to know which observations [latex] (y_i,\mathbf{x}_i)[/latex] will be kept in the learning population (at each draw). Note [latex]\mathcal{I}_{\bar b}=\{1,\cdots,n\}\setminus\mathcal{I}_b[/latex]. By noting [latex]\widehat{m}_{(b)} [/latex] built on sample [latex]\mathcal{I}_b[/latex], we then set :[latex display="true"]\widehat{\mathcal{R}}^{\text{ B}}=\frac{1}{B}\sum_{b=1}^B \mathcal{R}_b\text{ where }\mathcal{R}_b=\frac{n_{\overline{b}}}{n}\sum_{i\in\mathcal{I}_{\overline{b}}} \ell(y_i,\widehat{m}_{(b)}(\mathbf{x}_i))[/latex]where [latex]n_{\bar b}[/latex] is the number of observations that have not been kept in [latex]\mathcal{I}_b[/latex]. It should be noted that with this technique, on average [latex]e^{-1}\sim36.7\%[/latex] of the observations do not appear in the boosted sample, and we find an order of magnitude of the proportions used when creating a calibration sample, and a test sample. In fact, as Stone (1977) had shown, the minimization of AIC is to be compared to the cross-validation criterion, and Shao (1997) showed that the minimization of BIC corresponds to [latex]k[/latex]-fold cross-validation, with [latex]k=n/\log n[/latex].All those techniques here are mentioned in the “machine learning” section since they rely on automatic, computational techniques, and no probabilistic foundations are necessary. In many cases we did use the notation [latex]m^\star[/latex] (at least in the first posts on "machine learning" techniques) to highlight the fact that we want some sort of “optimal” model – and to make a distinction with estimators [latex]\widehat{m}[/latex] considered earlier, when we had some probabilistic framework. But of course, it is possible (and necessary) to build bridges between those two cultures…References are online here. As explained in the introduction, it is some sort of online version of an introduction to our joint paper with Emmanuel Flachaire and Antoine Ly, Econometrics and Machine Learning (initially writen in French), that will actually appear soon in the journal Economics and Statistics (in English and in French).