# Least-squares support vector machine

Least-squares support-vector machines (LS-SVM) for statistics and in statistical modeling, are least-squares versions of support-vector machines (SVM), which are a set of related supervised learning methods that analyze data and recognize patterns, and which are used for classification and regression analysis. In this version one finds the solution by solving a set of linear equations instead of a convex quadratic programming (QP) problem for classical SVMs. Least-squares SVM classifiers were proposed by Johan Suykens and Joos Vandewalle. LS-SVMs are a class of kernel-based learning methods.

## From support-vector machine to least-squares support-vector machine

Given a training set $\{x_{i},y_{i}\}_{i=1}^{N}$ with input data $x_{i}\in \mathbb {R} ^{n}$ and corresponding binary class labels $y_{i}\in \{-1,+1\}$, the SVM classifier, according to Vapnik's original formulation, satisfies the following conditions:
    ${\begin{cases}w^{T}\phi (x_{i})+b\geq 1,&{\text{if }}\quad y_{i}=+1,\\w^{T}\phi (x_{i})+b\leq -1,&{\text{if }}\quad y_{i}=-1,\end{cases}}$
which is equivalent to
    $y_{i}\left[{w^{T}\phi (x_{i})+b}\right]\geq 1,\quad i=1,\ldots ,N,$
where $\phi (x)$ is the nonlinear map from original space to the high- or infinite-dimensional space.

### Inseparable data

In case such a separating hyperplane does not exist, we introduce so-called slack variables $\xi _{i}$ such that
    ${\begin{cases}y_{i}\left[{w^{T}\phi (x_{i})+b}\right]\geq 1-\xi _{i},&i=1,\ldots ,N,\\\xi _{i}\geq 0,&i=1,\ldots ,N.\end{cases}}$
According to the structural risk minimization principle, the risk bound is minimized by the following minimization problem:
    $\min J_{1}(w,\xi )={\frac {1}{2}}w^{T}w+c\sum \limits _{i=1}^{N}\xi _{i},$
    ${\text{Subject to }}{\begin{cases}y_{i}\left[{w^{T}\phi (x_{i})+b}\right]\geq 1-\xi _{i},&i=1,\ldots ,N,\\\xi _{i}\geq 0,&i=1,\ldots ,N,\end{cases}}$
To solve this problem, we could construct the Lagrangian function:
    $L_{1}(w,b,\xi ,\alpha ,\beta )={\frac {1}{2}}w^{T}w+c\sum \limits _{i=1}^{N}{\xi _{i}}-\sum \limits _{i=1}^{N}\alpha _{i}\left\{y_{i}\left[{w^{T}\phi (x_{i})+b}\right]-1+\xi _{i}\right\}-\sum \limits _{i=1}^{N}\beta _{i}\xi _{i},$
where $\alpha _{i}\geq 0,\ \beta _{i}\geq 0\ (i=1,\ldots ,N)$ are the Lagrangian multipliers. The optimal point will be in the saddle point of the Lagrangian function, and then we obtain
| ${\begin{cases}{\frac {\partial L_{1}}{\partial w}}=0\quad \to \quad w=\sum \limits _{i=1}^{N}\alpha _{i}y_{i}\phi (x_{i}),\\{\frac {\partial L_{1}}{\partial b}}=0\quad \to \quad \sum \limits _{i=1}^{N}\alpha _{i}y_{i}=0,\\{\frac {\partial L_{1}}{\partial \xi _{i}}}=0\quad \to \quad \alpha _{i}+\beta _{i}=c,\;i=1,\ldots ,N\quad \to \quad 0\leq \alpha _{i}\leq c,\;i=1,\ldots ,N.\end{cases}}$ | (1) |
By substituting $w$ by its expression in the Lagrangian formed from the appropriate objective and constraints, we will get the following quadratic programming problem:
    $\max Q_{1}(\alpha )=-{\frac {1}{2}}\sum \limits _{i,j=1}^{N}{\alpha _{i}\alpha _{j}y_{i}y_{j}K(x_{i},x_{j})}+\sum \limits _{i=1}^{N}\alpha _{i},$
where $K(x_{i},x_{j})=\left\langle \phi (x_{i}),\phi (x_{j})\right\rangle$ is called the kernel function. Solving this QP problem subject to constraints in (1), we will get the hyperplane in the high-dimensional space and hence the classifier in the original space.

### Least-squares SVM formulation

The least-squares version of the SVM classifier is obtained by reformulating the minimization problem as
    $\min J_{2}(w,b,e)={\frac {\mu }{2}}w^{T}w+{\frac {\zeta }{2}}\sum \limits _{i=1}^{N}e_{i}^{2},$
subject to the equality constraints
    $y_{i}\left[{w^{T}\phi (x_{i})+b}\right]=1-e_{i},\quad i=1,\ldots ,N.$
The least-squares SVM (LS-SVM) classifier formulation above implicitly corresponds to a regression interpretation with binary targets $y_{i}=\pm 1$.
Using $y_{i}^{2}=1$, we have
    $\sum \limits _{i=1}^{N}e_{i}^{2}=\sum \limits _{i=1}^{N}(y_{i}e_{i})^{2}=\sum \limits _{i=1}^{N}e_{i}^{2}=\sum \limits _{i=1}^{N}\left(y_{i}-(w^{T}\phi (x_{i})+b)\right)^{2},$
with $e_{i}=y_{i}-(w^{T}\phi (x_{i})+b).$ Notice, that this error would also make sense for least-squares data fitting, so that the same end results holds for the regression case.
Hence the LS-SVM classifier formulation is equivalent to
    $J_{2}(w,b,e)=\mu E_{W}+\zeta E_{D}$
with $E_{W}={\frac {1}{2}}w^{T}w$ and $E_{D}={\frac {1}{2}}\sum \limits _{i=1}^{N}e_{i}^{2}={\frac {1}{2}}\sum \limits _{i=1}^{N}\left(y_{i}-(w^{T}\phi (x_{i})+b)\right)^{2}.$
Both $\mu$ and $\zeta$ should be considered as hyperparameters to tune the amount of regularization versus the sum squared error. The solution does only depend on the ratio $\gamma =\zeta /\mu$, therefore the original formulation uses only $\gamma$ as tuning parameter. We use both $\mu$ and $\zeta$ as parameters in order to provide a Bayesian interpretation to LS-SVM.
The solution of LS-SVM regressor will be obtained after we construct the Lagrangian function:
    ${\begin{cases}L_{2}(w,b,e,\alpha )\;=J_{2}(w,e)-\sum \limits _{i=1}^{N}\alpha _{i}\left\{{\left[{w^{T}\phi (x_{i})+b}\right]+e_{i}-y_{i}}\right\},\\\quad \quad \quad \quad \quad \;={\frac {1}{2}}w^{T}w+{\frac {\gamma }{2}}\sum \limits _{i=1}^{N}e_{i}^{2}-\sum \limits _{i=1}^{N}\alpha _{i}\left\{\left[w^{T}\phi (x_{i})+b\right]+e_{i}-y_{i}\right\},\end{cases}}$
where $\alpha _{i}\in \mathbb {R}$ are the Lagrange multipliers. The conditions for optimality are
    ${\begin{cases}{\frac {\partial L_{2}}{\partial w}}=0\quad \to \quad w=\sum \limits _{i=1}^{N}\alpha _{i}\phi (x_{i}),\\{\frac {\partial L_{2}}{\partial b}}=0\quad \to \quad \sum \limits _{i=1}^{N}\alpha _{i}=0,\\{\frac {\partial L_{2}}{\partial e_{i}}}=0\quad \to \quad \alpha _{i}=\gamma e_{i},\;i=1,\ldots ,N,\\{\frac {\partial L_{2}}{\partial \alpha _{i}}}=0\quad \to \quad y_{i}=w^{T}\phi (x_{i})+b+e_{i},\,i=1,\ldots ,N.\end{cases}}$
Elimination of $w$ and $e$ will yield a linear system instead of a quadratic programming problem:
    $\left[{\begin{matrix}0&1_{N}^{T}\\1_{N}&\Omega +\gamma ^{-1}I_{N}\end{matrix}}\right]\left[{\begin{matrix}b\\\alpha \end{matrix}}\right]=\left[{\begin{matrix}0\\Y\end{matrix}}\right],$
with $Y=[y_{1},\ldots ,y_{N}]^{T}$, $1_{N}=[1,\ldots ,1]^{T}$ and $\alpha =[\alpha _{1},\ldots ,\alpha _{N}]^{T}$. Here, $I_{N}$ is an $N\times N$ identity matrix, and $\Omega \in \mathbb {R} ^{N\times N}$ is the kernel matrix defined by $\Omega _{ij}=\phi (x_{i})^{T}\phi (x_{j})=K(x_{i},x_{j})$.

### Kernel function K

For the kernel function K(•, •) one typically has the following choices:
* Linear kernel : $K(x,x_{i})=x_{i}^{T}x,$
* Polynomial kernel of degree $d$: $K(x,x_{i})=\left({1+x_{i}^{T}x/c}\right)^{d},$
* Radial basis function RBF kernel : $K(x,x_{i})=\exp \left({-\left\|{x-x_{i}}\right\|^{2}/\sigma ^{2}}\right),$
* MLP kernel : $K(x,x_{i})=\tanh \left({k\,x_{i}^{T}x+\theta }\right),$
where $d$, $c$, $\sigma$, $k$ and $\theta$ are constants. Notice that the Mercer condition holds for all $c,\sigma \in \mathbb {R} ^{+}$ and $d\in N$ values in the polynomial and RBF case, but not for all possible choices of $k$ and $\theta$ in the MLP case. The scale parameters $c$, $\sigma$ and $k$ determine the scaling of the inputs in the polynomial, RBF and MLP kernel function. This scaling is related to the bandwidth of the kernel in statistics, where it is shown that the bandwidth is an important parameter of the generalization behavior of a kernel method.

## Bayesian interpretation for LS-SVM

A Bayesian interpretation of the SVM has been proposed by Smola et al. They showed that the use of different kernels in SVM can be regarded as defining different prior probability distributions on the functional space, as $P[f]\propto \exp \left({-\beta \left\|{{\hat {P}}f}\right\|^{2}}\right)$. Here $\beta >0$ is a constant and ${\hat {P}}$ is the regularization operator corresponding to the selected kernel.
A general Bayesian evidence framework was developed by MacKay, and MacKay has used it to the problem of regression, forward neural network and classification network. Provided data set $D$, a model $\mathbb {M}$ with parameter vector $w$ and a so-called hyperparameter or regularization parameter $\lambda$, Bayesian inference is constructed with 3 levels of inference:
* In level 1, for a given value of $\lambda$, the first level of inference infers the posterior distribution of $w$ by Bayesian rule
       $p(w|D,\lambda ,\mathbb {M} )\propto p(D|w,\mathbb {M} )p(w|\lambda ,\mathbb {M} ).$
* The second level of inference determines the value of $\lambda$, by maximizing
       $p(\lambda |D,\mathbb {M} )\propto p(D|\lambda ,\mathbb {M} )p(\lambda |\mathbb {M} ).$
* The third level of inference in the evidence framework ranks different models by examining their posterior probabilities
       $p(\mathbb {M} |D)\propto p(D|\mathbb {M} )p(\mathbb {M} ).$
We can see that Bayesian evidence framework is a unified theory for learning the model and model selection. Kwok used the Bayesian evidence framework to interpret the formulation of SVM and model selection. And he also applied Bayesian evidence framework to support vector regression.
Now, given the data points $\{x_{i},y_{i}\}_{i=1}^{N}$ and the hyperparameters $\mu$ and $\zeta$ of the model $\mathbb {M}$, the model parameters $w$ and $b$ are estimated by maximizing the posterior $p(w,b|D,\log \mu ,\log \zeta ,\mathbb {M} )$. Applying Bayes’ rule, we obtain
    $p(w,b|D,\log \mu ,\log \zeta ,\mathbb {M} )={\frac {p(D|w,b,\log \mu ,\log \zeta ,\mathbb {M} )p(w,b|\log \mu ,\log \zeta ,\mathbb {M} )}{p(D|\log \mu ,\log \zeta ,\mathbb {M} )}},$
where $p(D|\log \mu ,\log \zeta ,\mathbb {M} )$ is a normalizing constant such the integral over all possible $w$ and $b$ is equal to 1. We assume $w$ and $b$ are independent of the hyperparameter $\zeta$, and are conditional independent, i.e., we assume
    $p(w,b|\log \mu ,\log \zeta ,\mathbb {M} )=p(w|\log \mu ,\mathbb {M} )p(b|\log \sigma _{b},\mathbb {M} ).$
When $\sigma _{b}\to \infty$, the distribution of $b$ will approximate a uniform distribution. Furthermore, we assume $w$ and $b$ are Gaussian distribution, so we obtain the a priori distribution of $w$ and $b$ with $\sigma _{b}\to \infty$ to be
    ${\begin{array}{l}p(w,b|\log \mu ,)=\left({\frac {\mu }{2\pi }}\right)^{\frac {n_{f}}{2}}\exp \left({-{\frac {\mu }{2}}w^{T}w}\right){\frac {1}{\sqrt {2\pi \sigma _{b}}}}\exp \left({-{\frac {b^{2}}{2\sigma _{b}}}}\right)\\\quad \quad \quad \quad \quad \quad \quad \propto \left({\frac {\mu }{2\pi }}\right)^{\frac {n_{f}}{2}}\exp \left({-{\frac {\mu }{2}}w^{T}w}\right)\end{array}}.$
Here $n_{f}$ is the dimensionality of the feature space, same as the dimensionality of $w$.
The probability of $p(D|w,b,\log \mu ,\log \zeta ,\mathbb {M} )$ is assumed to depend only on $w,b,\zeta$ and $\mathbb {M}$. We assume that the data points are independently identically distributed (i.i.d.), so that:
    $p(D|w,b,\log \zeta ,\mathbb {M} )=\prod \limits _{i=1}^{N}{p(x_{i},y_{i}|w,b,\log \zeta ,\mathbb {M} )}.$
In order to obtain the least square cost function, it is assumed that the probability of a data point is proportional to:
    $p(x_{i},y_{i}|w,b,\log \zeta ,\mathbb {M} )\propto p(e_{i}|w,b,\log \zeta ,\mathbb {M} ).$
A Gaussian distribution is taken for the errors $e_{i}=y_{i}-(w^{T}\phi (x_{i})+b)$ as:
    $p(e_{i}|w,b,\log \zeta ,\mathbb {M} )={\sqrt {\frac {\zeta }{2\pi }}}\exp \left({-{\frac {\zeta e_{i}^{2}}{2}}}\right).$
It is assumed that the $w$ and $b$ are determined in such a way that the class centers ${\hat {m}}_{-}$ and ${\hat {m}}_{+}$ are mapped onto the target -1 and +1, respectively. The projections $w^{T}\phi (x)+b$ of the class elements $\phi (x)$ follow a multivariate Gaussian distribution, which have variance $1/\zeta$.
Combining the preceding expressions, and neglecting all constants, Bayes’ rule becomes
    $p(w,b|D,\log \mu ,\log \zeta ,\mathbb {M} )\propto \exp(-{\frac {\mu }{2}}w^{T}w-{\frac {\zeta }{2}}\sum \limits _{i=1}^{N}{e_{i}^{2}})=\exp(-J_{2}(w,b)).$
The maximum posterior density estimates $w_{MP}$ and $b_{MP}$ are then obtained by minimizing the negative logarithm of (26), so we arrive (10).