4.6 Support vector machines II
Based on the previous discussion, in this section we develop the final form of SVM.
The main conclusion from the previous sections is that the in-sample error is not an accurate estimate of the out-of-sample error and if we train a model with high complexity we may overfit the model. One way of dealing with this problem is to limit the complexity of the model, for example in terms of the VC-dimension. In the SVM case this could mean to limit the degree of the polynomial. Another way, which we will explore in this section, is to recall from the previous section that \[ E_{out} = E_{in} + \Omega(N,\mathcal H, \delta). \] Now instead of minimizing the in-sample error of our model, we add a term that represents \(\Omega\), which is increasing in the complexity of the model. Then the learning problem instead becomes, \[ \min_{h\in\mathcal H}\left[ E_{in}(h) + c(h)\right], \] where \(c\) is some function that increases with the complexity of the function \(h\). SVMs are a special case of this. If we have a linear classifier \(f(x) = \beta_0+\beta_1x^1 + \ldots \beta_p x^p\) the optimisation problem is \[ \min_{\beta_0,\beta_1,\ldots,\beta_p} \sum_{i=1}^n \left( 1-y_if(x_i) \right)_+ + \lambda \sum_{i=1}^p{\beta_j^2}, \] where \(\lambda\geq 0\) is a tuning parameter. Here a large value of \(\lambda\) will penalize complex models heavily and force the model to be simple, thereby preventing overfitting. A small value of \(\lambda\) will allow more complex models, thereby making the in-sample error smaller, on the other hand risking overfitting.
As usual, we may take some function of the inputs \(\varphi_i(x)\) and consider a linear function of these new features. Let us see what happens when we vary \(\lambda\), using polynomial \(\varphi\) of maximum degree 5.
Figure 4.14: Error vs. reciprocal of lambda.
We see from the picture that \(\lambda\) controls the complexity of the model. When \(\lambda\) is large (\(1/\lambda\) small), the in-sample and out-of-sample errors are similar and as \(\lambda\) becomes smaller, the in-sample error becomes smaller, but the difference between the errors are larger.
With this development, we do not need to limit the complexity of the class of function \(\mathcal H\), since this is done by choosing \(\lambda\). In fact, we can in some cases even choose \(\mathcal H\) to be an infinite dimensional space of functions.
It turns out that the solution to the optimization problem of SVM can be written as \[ f(x) = \beta_0 + \sum_{i=1}^n\alpha_i\langle x,x_i \rangle, \] for some values \(\alpha_i\), where we define the inner product of two points \(x\) and \(\tilde x\) as, \[ \langle x,\tilde x \rangle = \sum_{j=1}^p x^j\tilde x^j. \] If we now instead consider the input features \(\varphi(x) = (\varphi_1(x),\ldots,\varphi_M(x))\) and functions of the form \[ f(x) = \beta_0 + \varphi_1(x)\beta_1 + \ldots \varphi_M(x)\beta_M , \] in the same way as above, the SVM classifier is \[ f(x) = \beta_0 + \sum_{i=1}^n\alpha_i\langle \varphi(x),\varphi(x_i) \rangle. \] We then see that the features \(\varphi\) only appears in the inner product. So it is enough if we specify the function \[ K(x,x_i):= \langle \varphi(x),\varphi(x_i) \rangle, \] which is called a kernel. We then write \[ f(x) = \beta_0 + \sum_{i=1}^n\alpha_iK(x,x_i). \] An important point here is that the dimension of \(\varphi\), \(M\), does not appear here. The sum is over (at most) \(n\) terms, even if let \(M\to\infty\).
In practice, we therefore specify the kernel and not the features. Two examples of kernels are the polynomial kernel \[ K(x,\tilde x) = (1+\sum_{i=1}^px_i\tilde x_i)^d, \] and the radial basis kernel, \[ K(x,\tilde x) = \exp\left( -\gamma \sum_{i=1}^p (x_i-\tilde x_i)^2\right). \] Let us try the radial basis function kernel on our data set.
Figure 4.15: Training data a radial basis SVM classification
This now has an in-sample error of 0.275 and out-of-sample error 0.255555