Support vector machine (SVM), as a shallow model, has been widely applied for classification tasks. To solve the model, groups of super vectors (SVs) of corresponding classes are extracted, so as to calculate a hyperplane as the classification boarder.

A brief review

Denote as the samples to be classified, and $y = \{y_1,~y_2,~\dots,~y_N\}$ are the corresponding labels. Take binary classification as an example,

where are the coefficients w.r.t. features in , b is the bias.

The the problem becomes an optimization task, where the object is,

which shall be calculated with Lagrange equation,

To save time, it usually selects a subset of namely super vectors to optimize above equation, instead of all of the samples. Those SVs are samples that stand close to the classification hyperplane, i.e., the boarders of different types. They are considered on behalf of the classes they belonging to.

By solving the Lagrange equation, we obtain the , as well as and $b$.

where and are arbitrary super vectors of class one and two, respectively.

The dicision function based on those parameters are,

here is the sign function.

For non-linear classification, which is more general than linear case, the dot product between and are replaced by non-linear kernel functions $\Phi(\cdot)$, i.e.,

Realization and visualization

With the help of libsvm, it is easy to realize SVM based classification. What I want to say in this blog is how to visualize or replicate the prediction stage of the svmtrain function. Some comments are as follows,

  • After training the SVM with svmtrain, a model will be generated;
  • In the model, super vectors, parameters like weights and bias, are archived;
  • To save space, the support vectors are saved as sparse matrix.
  • For multi-class classification, it can be transformed to multiple binary-classification tasks.

Here is a naive two-dimensional three-type classification example (code is available). I divided three-class task into three binary classifications. The linear kernel function was used, thus the classification hyperplanes were also linear.


In the right figure, only support vector points are plotted. It can be found that the SVs are those points stand at the boarder between different categories.

Comment and share

  • page 1 of 1
Author's picture

Jason Ma

We are in the same story.


Astronomer? Software engineer


Shanghai