Search Knowledge

© 2026 LIBREUNI PROJECT

Machine Learning / Supervised Learning

Support Vector Machines

Support Vector Machines

A Support Vector Machine (SVM) is a supervised algorithm that finds the decision boundary (hyperplane) that maximizes the margin between classes.

Margin Maximization and Slack Variables

In linear classification, we find a hyperplane wTx+b=0w^T x + b = 0 that separates classes.

Primal Optimization Problem (Soft Margin)

To allow for noise and misclassifications, we introduce slack variables ξi0\xi_i \ge 0. The objective minimizes:

minw,b,ξ12w2+Ci=1mξi\min_{w, b, \xi} \frac{1}{2} ||w||^2 + C \sum_{i=1}^{m} \xi_i

subject to:

y(i)(wTx(i)+b)1ξiandξi0y^{(i)} (w^T x^{(i)} + b) \ge 1 - \xi_i \quad \text{and} \quad \xi_i \ge 0

The parameter CC controls the trade-off: a small CC allows more margin violations (regularized), while a large CC forces a hard margin (sensitive to noise).

The Dual Formulation and the Kernel Trick

By reformulating the optimization problem using Lagrange multipliers, we express the decision function using inner products of training instances:

h(x)=i=1mαiy(i)(x(i)x)+bh(x) = \sum_{i=1}^{m} \alpha_i y^{(i)} (x^{(i)} \cdot x) + b

The coefficients αi\alpha_i are non-zero only for instances on the margin boundaries. These are the Support Vectors that determine the decision boundary.

The Kernel Trick

The kernel trick replaces the dot product with a kernel function K(x(i),x(j))K(x^{(i)}, x^{(j)}), avoiding mapping data to high-dimensional spaces explicitly.

  • Polynomial Kernel: K(x,z)=(γxTz+r)dK(x, z) = (\gamma x^T z + r)^d
  • Radial Basis Function (RBF) Kernel: K(x,z)=exp(γxz2)K(x, z) = \exp(-\gamma ||x - z||^2)

The parameter γ\gamma controls the RBF width: a larger γ\gamma makes the boundary narrower and more irregular, fitting specific instances.

Example: Non-Linear Kernel SVM

The following example demonstrates training an SVM with an RBF kernel:

python

Interactive Lab

Train an RBF kernel SVM to solve the non-linear XOR problem. Inspect the support vectors selected by the model.

Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare

Exercise

Test your understanding of SVM margin constraints:

What happens to the decision boundary if we increase the hyperparameter C to infinity?

References & Further Reading

Next Module Decision Trees