HomeProjectsNotes
Theme
Back to Notes

Support Vector Machines & Their Applications

2026-04-24

Machine Learning — Lecture Notes A complete beginner-friendly guide covering theory, mathematics, kernel methods, and real-world applications


Table of Contents

  1. Linear Classifiers
  2. Classifier Margin
  3. Maximum Margin & Linear SVM
  4. SVM Mathematics
  5. Solving the Optimization Problem
  6. Noisy Data & Soft Margin Classification
  7. Non-linear SVMs & the Kernel Trick
  8. Properties of SVM
  9. Real-World Applications
  10. Limitations of SVM

Linear Classifiers

A classifier is a function that takes a data point and assigns it to one of several predefined classes. In the binary case, we have two classes — conventionally labeled +1 and −1.

A linear classifier separates these classes using a straight line (in 2D), a plane (in 3D), or more generally a hyperplane in higher-dimensional space.

Core Formula

f ( x , w , b ) = sign ( w ⋅ x + b ) f(\mathbf{x}, \mathbf{w}, b) = \text{sign}(\mathbf{w} \cdot \mathbf{x} + b) f(x,w,b)=sign(w⋅x+b)

  • w \mathbf{w} w — the weight vector, which is perpendicular to the decision boundary and controls its orientation
  • x \mathbf{x} x — the input feature vector (your data point)
  • b b b — the bias (also called intercept), which shifts the boundary away from the origin
  • The output is +1 or −1 depending on which side of the hyperplane the point falls

How the Decision Rule Works

The expression w ⋅ x + b \mathbf{w} \cdot \mathbf{x} + b w⋅x+b computes a score for each input:

  • Score > 0 → classify as +1 (positive class)
  • Score < 0 → classify as −1 (negative class)
  • Score = 0 → the point lies exactly on the decision boundary

VISUAL CONCEPT — LINEAR DECISION BOUNDARY

The Fundamental Problem: Infinitely Many Valid Boundaries

When two classes are perfectly separable, there exist infinitely many hyperplanes that correctly separate them. Each gives zero training error, but they will generalize differently on unseen data. This raises the key question:

Which hyperplane should we choose?

This is precisely the problem Support Vector Machines are designed to solve.


Classifier Margin

The margin is the distance between the decision boundary and the nearest data points from either class. These nearest points are called support vectors (introduced formally in the next section).

Intuitive Analogy

Think of building a road between two rows of houses. The margin is the road's total width. A wider road is safer — vehicles (new data points) have more room before hitting a house (being misclassified). You want to build the widest road possible.

MARGIN — THE GAP BETWEEN THE BOUNDARY AND NEAREST DATA POINTS

Why a Larger Margin Generalizes Better

A boundary with a large margin is more robust to perturbations. If new data arrives slightly displaced from the training data, a large-margin classifier is less likely to misclassify it. This is formally justified by PAC (Probably Approximately Correct) learning theory, which proves:

Generalization error ≤ f  ⁣ ( 1 margin ) \text{Generalization error} \leq f\!\left(\frac{1}{\text{margin}}\right) Generalization error≤f(margin1​)

In other words, maximizing the margin directly minimizes an upper bound on future classification error.


Maximum Margin & Linear SVM

The Support Vector Machine finds the unique hyperplane that maximizes the margin between the two classes. This is also called the Maximum Margin Classifier or Linear SVM (LSVM).

★ Key Insight

The data points lying exactly on the margin boundaries are the support vectors. They are the only points that define the optimal hyperplane. All other training points are irrelevant — you could remove them without changing the result.

Property Explanation
Maximizing margin is principled Both geometric intuition and PAC learning theory confirm that a larger margin improves generalization.
Only support vectors matter After training, the classifier depends only on support vectors. Other points have no influence on the boundary.
Strong empirical performance SVM consistently achieves excellent results, especially on high-dimensional data.

SVM Mathematics

Defining the Three Key Hyperplanes

We define three parallel hyperplanes that characterize the SVM solution:

Decision boundary (the central separating hyperplane): w ⋅ x + b = 0 \mathbf{w} \cdot \mathbf{x} + b = 0 w⋅x+b=0

Positive margin boundary H + H_+ H+​ (touches positive support vectors): w ⋅ x + + b = + 1 \mathbf{w} \cdot \mathbf{x}^+ + b = +1 w⋅x++b=+1

Negative margin boundary H − H_- H−​ (touches negative support vectors): w ⋅ x − + b = − 1 \mathbf{w} \cdot \mathbf{x}^- + b = -1 w⋅x−+b=−1

The constraints require that no training point falls between these two margin boundaries:

y i ( w ⋅ x i + b ) ≥ 1 ∀ i y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1 \quad \forall i yi​(w⋅xi​+b)≥1∀i

Computing the Margin Width

Step 1 — Pick one point from each boundary.

Let x + \mathbf{x}^+ x+ be a support vector on H + H_+ H+​ and x − \mathbf{x}^- x− be a support vector on H − H_- H−​. By definition:

w ⋅ x + + b = + 1 \mathbf{w} \cdot \mathbf{x}^+ + b = +1 w⋅x++b=+1 w ⋅ x − + b = − 1 \mathbf{w} \cdot \mathbf{x}^- + b = -1 w⋅x−+b=−1

Step 2 — Subtract to relate the two points.

( w ⋅ x + ) − ( w ⋅ x − ) = 1 − ( − 1 ) = 2 (\mathbf{w} \cdot \mathbf{x}^+) - (\mathbf{w} \cdot \mathbf{x}^-) = 1 - (-1) = 2 (w⋅x+)−(w⋅x−)=1−(−1)=2 w ⋅ ( x + − x − ) = 2 \mathbf{w} \cdot (\mathbf{x}^+ - \mathbf{x}^-) = 2 w⋅(x+−x−)=2

Step 3 — Project onto the normal direction w \mathbf{w} w.

The vector ( x + − x − ) (\mathbf{x}^+ - \mathbf{x}^-) (x+−x−) points from H − H_- H−​ to H + H_+ H+​ but is not necessarily perpendicular to the boundaries. The perpendicular distance (the margin M M M) is obtained by projecting onto the unit normal w ^ = w ∥ w ∥ \hat{\mathbf{w}} = \frac{\mathbf{w}}{\|\mathbf{w}\|} w^=∥w∥w​:

M = ( x + − x − ) ⋅ w ∥ w ∥ = w ⋅ ( x + − x − ) ∥ w ∥ M = (\mathbf{x}^+ - \mathbf{x}^-) \cdot \frac{\mathbf{w}}{\|\mathbf{w}\|} = \frac{\mathbf{w} \cdot (\mathbf{x}^+ - \mathbf{x}^-)}{\|\mathbf{w}\|} M=(x+−x−)⋅∥w∥w​=∥w∥w⋅(x+−x−)​

Step 4 — Substitute the result from Step 2.

M = 2 ∥ w ∥ \boxed{M = \frac{2}{\|\mathbf{w}\|}} M=∥w∥2​​

Optimization Objective

To maximize the margin m = 2 ∥ w ∥ m = \frac{2}{\|\mathbf{w}\|} m=∥w∥2​, we minimize ∥ w ∥ \|\mathbf{w}\| ∥w∥. For convenience, we minimize the squared norm:

min ⁡ w , b 1 2 ∥ w ∥ 2 \min_{\mathbf{w}, b} \quad \frac{1}{2}\|\mathbf{w}\|^2 w,bmin​21​∥w∥2

subject to:

y i ( w ⋅ x i + b ) ≥ 1 , ∀ i y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \ge 1, \quad \forall i yi​(w⋅xi​+b)≥1,∀i

This is a convex quadratic program with linear constraints — it has a unique global minimum and can be solved efficiently.

Solving the Optimization Problem

Why Use Lagrange Multipliers?

The SVM optimization has linear constraints, making it ideal for the Lagrangian method. Rather than solving the constrained problem directly, we transform it into an unconstrained dual problem that is often easier to solve and reveals important structure.

Step 1 — Form the Lagrangian

Introduce a non-negative multiplier α i ≥ 0 \alpha_i \geq 0 αi​≥0 for each training constraint:

L ( w , b , α ) = 1 2 ∥ w ∥ 2 − ∑ i = 1 n α i [ y i ( w ⋅ x i + b ) − 1 ] L(\mathbf{w}, b, \boldsymbol{\alpha}) = \frac{1}{2}\|\mathbf{w}\|^2 - \sum_{i=1}^{n} \alpha_i \left[ y_i(\mathbf{w} \cdot \mathbf{x}_i + b) - 1 \right] L(w,b,α)=21​∥w∥2−i=1∑n​αi​[yi​(w⋅xi​+b)−1]

At the optimum, increasing any α i \alpha_i αi​ for a non-binding constraint does not help, so the Lagrangian captures all the information in the original problem.

Step 2 — Derive Stationarity Conditions

Setting the partial derivatives to zero:

∂ L ∂ w = 0    ⟹    w = ∑ i = 1 n α i y i x i \frac{\partial L}{\partial \mathbf{w}} = 0 \implies \mathbf{w} = \sum_{i=1}^{n} \alpha_i y_i \mathbf{x}_i ∂w∂L​=0⟹w=i=1∑n​αi​yi​xi​ ∂ L ∂ b = 0    ⟹    ∑ i = 1 n α i y i = 0 \frac{\partial L}{\partial b} = 0 \implies \sum_{i=1}^{n} \alpha_i y_i = 0 ∂b∂L​=0⟹i=1∑n​αi​yi​=0

Important: The weight vector w \mathbf{w} w is a linear combination of the training points, weighted by their α i \alpha_i αi​ values. Points with α i = 0 \alpha_i = 0 αi​=0 contribute nothing — these are the non-support vectors.

Step 3 — The Dual Problem

Substituting the stationarity conditions back into the Lagrangian eliminates w \mathbf{w} w and b b b, yielding the dual problem:

max ⁡ α Q ( α ) = ∑ i = 1 n α i − 1 2 ∑ i = 1 n ∑ j = 1 n α i α j   y i y j   ( x i ⋅ x j ) \max_{\boldsymbol{\alpha}} \quad Q(\boldsymbol{\alpha}) = \sum_{i=1}^{n} \alpha_i - \frac{1}{2} \sum_{i=1}^{n}\sum_{j=1}^{n} \alpha_i \alpha_j \, y_i y_j \, (\mathbf{x}_i \cdot \mathbf{x}_j) αmax​Q(α)=i=1∑n​αi​−21​i=1∑n​j=1∑n​αi​αj​yi​yj​(xi​⋅xj​)

Subject to:

∑ i = 1 n α i y i = 0 , α i ≥ 0 ∀ i \sum_{i=1}^{n} \alpha_i y_i = 0, \qquad \alpha_i \geq 0 \quad \forall i i=1∑n​αi​yi​=0,αi​≥0∀i

Key Observations

1. Sparsity: After solving, most α i = 0 \alpha_i = 0 αi​=0. Only the support vectors have α i > 0 \alpha_i > 0 αi​>0. This means the classifier stores and uses only a small subset of training data.

2. Data appears only as dot products x i ⋅ x j \mathbf{x}_i \cdot \mathbf{x}_j xi​⋅xj​: This is the critical structural property that enables the kernel trick (Section 07). We can replace dot products with any valid kernel without changing the optimization procedure.

Making Predictions

Once α \boldsymbol{\alpha} α is found, the bias b b b is recovered from any support vector:

b = y k − w ⋅ x k for any support vector  k  where  α k > 0 b = y_k - \mathbf{w} \cdot \mathbf{x}_k \quad \text{for any support vector } k \text{ where } \alpha_k > 0 b=yk​−w⋅xk​for any support vector k where αk​>0

The classifier for a new point x \mathbf{x} x is:

f ( x ) = sign  ⁣ ( ∑ i : α i > 0 α i y i ( x i ⋅ x ) + b ) f(\mathbf{x}) = \text{sign}\!\left(\sum_{i: \alpha_i > 0} \alpha_i y_i (\mathbf{x}_i \cdot \mathbf{x}) + b\right) f(x)=sign(i:αi​>0∑​αi​yi​(xi​⋅x)+b)

Noisy Data & Soft Margin Classification

The Problem with Hard Margin SVM

The formulation above assumes data is perfectly linearly separable — no overlap, no noise, no outliers. In practice:

  • Real-world data almost always has noise and mislabeled examples
  • Forcing zero training error on noisy data causes overfitting: the boundary contorts to accommodate every outlier and performs poorly on new data
  • For slightly non-separable data, the hard margin problem is infeasible (no solution exists)

Solution: Slack Variables (Soft Margin SVM)

We introduce slack variables ξ i ≥ 0 \xi_i \geq 0 ξi​≥0, one per training point, that allow controlled violation of the margin constraints.

Interpretation of ξ i \xi_i ξi​:

Value Meaning
ξ i = 0 \xi_i = 0 ξi​=0 Point is correctly classified and outside the margin — no violation
0 < ξ i ≤ 1 0 < \xi_i \leq 1 0<ξi​≤1 Point is correctly classified but falls inside the margin
ξ i > 1 \xi_i > 1 ξi​>1 Point is misclassified

The Soft Margin Optimization Problem

min ⁡ w , b , ξ 1 2 ∥ w ∥ 2 + C ∑ i = 1 n ξ i \min_{\mathbf{w}, b, \boldsymbol{\xi}} \quad \frac{1}{2}\|\mathbf{w}\|^2 + C \sum_{i=1}^{n} \xi_i w,b,ξmin​21​∥w∥2+Ci=1∑n​ξi​

Subject to:

y i ( w ⋅ x i + b ) ≥ 1 − ξ i , ξ i ≥ 0 ∀ i y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1 - \xi_i, \qquad \xi_i \geq 0 \quad \forall i yi​(w⋅xi​+b)≥1−ξi​,ξi​≥0∀i

The objective has two competing terms:

  • 1 2 ∥ w ∥ 2 \frac{1}{2}\|\mathbf{w}\|^2 21​∥w∥2 — maximize the margin
  • C ∑ i ξ i C \sum_i \xi_i C∑i​ξi​ — minimize total margin violations

The Role of the Regularization Parameter C

C Value Effect Risk
Large C C C Penalizes violations heavily; tries to classify all training points correctly Overfitting to noise
Small C C C Tolerates more violations in exchange for a wider margin Underfitting if C is too small

In practice, C C C is chosen using cross-validation.

Hard vs. Soft Margin Comparison

Hard Margin SVM Soft Margin SVM
Requires perfectly separable data Handles overlapping, noisy data
Infeasible if data overlaps Always has a solution
Zero training misclassifications Allows controlled misclassifications
Constraint: y i ( w ⋅ x i + b ) ≥ 1 y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1 yi​(w⋅xi​+b)≥1 Constraint: y i ( w ⋅ x i + b ) ≥ 1 − ξ i y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1 - \xi_i yi​(w⋅xi​+b)≥1−ξi​
No tuning parameter Tuning parameter C C C controls bias-variance trade-off

Non-linear SVMs & the Kernel Trick

When Linear Boundaries Are Insufficient

Some datasets cannot be separated by any hyperplane. Consider a ring of red points surrounded by blue points — no straight line separates them. A linear SVM will fail here regardless of the margin.

The Core Idea: Feature Space Mapping

The key insight is to map the data into a higher-dimensional feature space F \mathcal{F} F using a function ϕ : R d → F \phi: \mathbb{R}^d \to \mathcal{F} ϕ:Rd→F, where the classes become linearly separable. We then apply a linear SVM in this higher-dimensional space.

Example

Consider 2D data lying on concentric circles (not linearly separable). Add a third feature z = x 1 2 + x 2 2 z = x_1^2 + x_2^2 z=x12​+x22​. In 3D space, the inner circle has small z z z values and the outer circle has large z z z values — they are now separated by the plane z = c z = c z=c. This plane corresponds to a circle in the original 2D space.

NON-LINEAR MAPPING: 2D → HIGHER-DIMENSIONAL SPACE

The Computational Problem — and Its Elegant Solution

Explicitly computing ϕ ( x ) \phi(\mathbf{x}) ϕ(x) for a very high (or infinite) dimensional space is prohibitively expensive. However, notice that in the SVM dual problem, data only appears as dot products x i ⋅ x j \mathbf{x}_i \cdot \mathbf{x}_j xi​⋅xj​. After mapping, these become ϕ ( x i ) ⋅ ϕ ( x j ) \phi(\mathbf{x}_i) \cdot \phi(\mathbf{x}_j) ϕ(xi​)⋅ϕ(xj​).

A kernel function computes this dot product directly in the original space, without ever computing ϕ ( x ) \phi(\mathbf{x}) ϕ(x) explicitly:

K ( x i , x j ) = ϕ ( x i ) ⋅ ϕ ( x j ) K(\mathbf{x}_i, \mathbf{x}_j) = \phi(\mathbf{x}_i) \cdot \phi(\mathbf{x}_j) K(xi​,xj​)=ϕ(xi​)⋅ϕ(xj​)

This is the kernel trick: replace every dot product with a kernel evaluation, and the SVM works implicitly in a potentially infinite-dimensional space at the cost of computing n × n n \times n n×n kernel values.

Worked Example — Polynomial Kernel

For 2D vectors x = [ x 1 , x 2 ] T \mathbf{x} = [x_1, x_2]^T x=[x1​,x2​]T, the kernel K ( x i , x j ) = ( 1 + x i T x j ) 2 K(\mathbf{x}_i, \mathbf{x}_j) = (1 + \mathbf{x}_i^T \mathbf{x}_j)^2 K(xi​,xj​)=(1+xiT​xj​)2 implicitly corresponds to the 6-dimensional mapping:

ϕ ( x ) = [ 1 ,   x 1 2 ,   2   x 1 x 2 ,   x 2 2 ,   2   x 1 ,   2   x 2 ] T \phi(\mathbf{x}) = [1,\ x_1^2,\ \sqrt{2}\,x_1 x_2,\ x_2^2,\ \sqrt{2}\,x_1,\ \sqrt{2}\,x_2]^T ϕ(x)=[1, x12​, 2 ​x1​x2​, x22​, 2 ​x1​, 2 ​x2​]T

The kernel computes the 6D dot product using only 2D arithmetic — a significant computational saving.

What Makes a Valid Kernel? (Mercer's Theorem)

A function K ( x i , x j ) K(\mathbf{x}_i, \mathbf{x}_j) K(xi​,xj​) is a valid kernel if and only if the Gram matrix G G G with entries G i j = K ( x i , x j ) G_{ij} = K(\mathbf{x}_i, \mathbf{x}_j) Gij​=K(xi​,xj​) is symmetric and positive semi-definite for any set of inputs. You do not need to explicitly construct ϕ \phi ϕ — just verify this condition.

Common Kernel Functions

Kernel Formula Best Used When
Linear K ( x i , x j ) = x i T x j K(\mathbf{x}_i, \mathbf{x}_j) = \mathbf{x}_i^T \mathbf{x}_j K(xi​,xj​)=xiT​xj​ Data is already linearly separable; very high-dimensional (e.g., text)
Polynomial (degree p p p) K ( x i , x j ) = ( 1 + x i T x j ) p K(\mathbf{x}_i, \mathbf{x}_j) = (1 + \mathbf{x}_i^T \mathbf{x}_j)^p K(xi​,xj​)=(1+xiT​xj​)p Text classification; polynomial decision boundaries
Gaussian / RBF K ( x i , x j ) = exp ⁡  ⁣ ( − ∥ x i − x j ∥ 2 2 σ 2 ) K(\mathbf{x}_i, \mathbf{x}_j) = \exp\!\left(-\dfrac{\|\mathbf{x}_i - \mathbf{x}_j\|^2}{2\sigma^2}\right) K(xi​,xj​)=exp(−2σ2∥xi​−xj​∥2​) General-purpose default; smooth, locally varying boundaries
Sigmoid K ( x i , x j ) = tanh ⁡ ( β 0   x i T x j + β 1 ) K(\mathbf{x}_i, \mathbf{x}_j) = \tanh(\beta_0 \,\mathbf{x}_i^T \mathbf{x}_j + \beta_1) K(xi​,xj​)=tanh(β0​xiT​xj​+β1​) Resembles neural network activation; only valid for certain parameters

The Non-linear SVM Dual Problem

Replacing dot products with kernel evaluations in the dual:

max ⁡ α Q ( α ) = ∑ i α i − 1 2 ∑ i ∑ j α i α j   y i y j   K ( x i , x j ) \max_{\boldsymbol{\alpha}} \quad Q(\boldsymbol{\alpha}) = \sum_i \alpha_i - \frac{1}{2} \sum_i \sum_j \alpha_i \alpha_j \, y_i y_j \, K(\mathbf{x}_i, \mathbf{x}_j) αmax​Q(α)=i∑​αi​−21​i∑​j∑​αi​αj​yi​yj​K(xi​,xj​)

The decision function becomes:

f ( x ) = sign  ⁣ ( ∑ i :   α i > 0 α i y i   K ( x i , x ) + b ) f(\mathbf{x}) = \text{sign}\!\left(\sum_{i:\, \alpha_i > 0} \alpha_i y_i \, K(\mathbf{x}_i, \mathbf{x}) + b\right) f(x)=sign(i:αi​>0∑​αi​yi​K(xi​,x)+b)

The optimization algorithm is identical to the linear case — only the inner products are replaced by kernel evaluations.


Properties of SVM

Property Description
Flexible similarity measure The kernel function defines what "similar" means. You can design custom kernels for strings, graphs, images, or any structured data.
Sparse solution Only support vectors ( α i > 0 \alpha_i > 0 αi​>0) are stored and used at prediction time. For large datasets, this can be a tiny fraction of the training data.
Handles high-dimensional data Generalization bounds depend on the margin, not the number of features. SVM does not degrade as dimensionality increases — unlike many other classifiers.
Overfitting control The regularization parameter C C C in soft-margin SVM provides a direct, principled mechanism to balance fitting the training data and generalizing to new data.
Guaranteed global optimum The primal objective 1 2 ∥ w ∥ 2 \frac{1}{2}\|\mathbf{w}\|^2 21​∥w∥2 is convex and the constraints are linear. The optimization has exactly one global minimum — no local minima exist.
Implicit feature selection In the linear SVM, the squared weight w j 2 w_j^2 wj2​ quantifies the contribution of feature j j j. Features with small weights can be pruned without significant performance loss.

Real-World Applications

Application 1 — Cancer Classification via Gene Expression Data

The Challenge

Challenge Details
High dimensionality ( p ≫ n p \gg n p≫n) Thousands of gene expression measurements per patient, but typically fewer than 100 patients. Standard methods break down in this regime.
Class imbalance Far fewer cancer-positive than cancer-negative samples. Naive classifiers are biased toward the majority class.
Noisy, irrelevant features Most genes are unrelated to the cancer subtype being classified. They contribute noise that can mislead other classifiers.

How SVM Addresses Each Challenge

Handling imbalance: A modified kernel adds a correction term proportional to the fraction of positive samples:

K ′ ( x , x ) = K ( x , x ) + λ ⋅ n + N K'(\mathbf{x}, \mathbf{x}) = K(\mathbf{x}, \mathbf{x}) + \lambda \cdot \frac{n^+}{N} K′(x,x)=K(x,x)+λ⋅Nn+​

where n + n^+ n+ is the number of positive training examples and N N N is the total. This re-balances the effective cost of misclassifying minority-class examples.

Feature selection: In the linear SVM, the weight magnitude w j 2 w_j^2 wj2​ ranks each gene by importance. Genes with very small weights are likely irrelevant and can be removed — a process called recursive feature elimination (RFE).

High-dimensional stability: SVM's generalization bound depends on the margin, not the number of features. This makes it particularly well-suited to the p ≫ n p \gg n p≫n regime of genomic data.

Known Limitation

SVM is sensitive to label noise (mislabeled training examples). Even a small fraction of incorrectly labeled patients can significantly degrade classification performance. Careful data curation is essential.


Application 2 — Text Categorization

The Task

Automatically assign text documents (news articles, emails, web pages) to predefined categories. Since a document can belong to multiple categories, this is decomposed into a set of independent binary classification problems — one per category (e.g., "politics vs. not politics", "sports vs. not sports").

Representing Documents as Vectors: Bag of Words (TF-IDF)

Before SVM can process text, documents must be converted to numerical vectors:

  1. Build a vocabulary of all words appearing in the training corpus (after preprocessing).
  2. Preprocess: Remove stop words ("the", "is", "a") and apply stemming (map "running", "runs", "ran" → "run").
  3. Assign TF-IDF weights to each word per document:
ϕ j ( x ) = tf j ⋅ log ⁡ ( idf j )   /   κ \phi_j(\mathbf{x}) = \text{tf}_j \cdot \log(\text{idf}_j)\ /\ \kappa ϕj​(x)=tfj​⋅log(idfj​) / κ

where tf j \text{tf}_j tfj​ is the term frequency (how often word j j j appears in the document), idf j = N / df j \text{idf}_j = N / \text{df}_j idfj​=N/dfj​ is the inverse document frequency ( df j \text{df}_j dfj​ = number of documents containing word j j j, N N N = total documents), and κ \kappa κ is a normalization constant. This down-weights common words and up-weights discriminative words.

  1. The result is a sparse, high-dimensional vector where most entries are zero (most words don't appear in any given document).

Why SVM Is a Natural Fit for Text

Reason Explanation
Very high dimensionality Vocabularies of 50,000–100,000 words are common. SVM handles this natively; many other classifiers cannot.
Sparse instances Each document uses only a tiny fraction of all vocabulary words. SVM's sparse support vector structure aligns perfectly with this.
Dense concept structure Unlike gene data, most words are relevant to at least some categories. There are few truly irrelevant features.
Empirical linear separability Text categorization problems have been found to be approximately linearly separable in high-dimensional word space. Linear SVM is therefore both fast and effective.

Limitations of SVM

Limitations 1 — Sensitivity to Label Noise

Mislabeled training examples can have a disproportionate effect on the decision boundary (particularly if they become support vectors). This is especially problematic in medical applications where annotation errors are common.

Limitations 2 — Inherently Binary

Standard SVM is formulated for two-class problems. Real tasks often require distinguishing among m > 2 m > 2 m>2 classes.

Extending SVM to Multi-class Problems

The standard approach is one-vs-rest (OvR) classification:

  1. Train m m m separate SVMs. SVM- k k k is trained to distinguish class k k k from all other classes (positive label = class k k k, negative label = all others).
  2. To classify a new point x \mathbf{x} x, evaluate all m m m classifiers.
  3. Assign the class whose classifier gives the largest positive score (i.e., the point is furthest into the positive region):
y ^ = arg ⁡ max ⁡ k ( w k ⋅ x + b k ) \hat{y} = \arg\max_{k} \left( \mathbf{w}_k \cdot \mathbf{x} + b_k \right) y^​=argkmax​(wk​⋅x+bk​)

Practical Guidelines for Applying SVM

Decision Recommendation
Kernel selection Start with the RBF (Gaussian) kernel as a default. Use a linear kernel for very high-dimensional data (text, genomics). Design custom kernels for structured inputs (graphs, sequences).
Setting σ \sigma σ in RBF kernel Initialize σ \sigma σ to the average or median pairwise distance between training points of different classes. Tune further with cross-validation.
Setting C C C (regularization) Use k k k-fold cross-validation or a held-out validation set. There is no universal optimal value — it depends on the noise level and overlap in your data.

★ Summary

SVM remains one of the most theoretically well-grounded classifiers in machine learning. Its convex optimization guarantees a unique global solution. The kernel trick provides principled non-linear generalization at manageable computational cost. The soft margin formulation handles real-world noise robustly. Despite the rise of deep learning, SVM continues to be competitive — and often superior — on small, high-dimensional datasets such as those encountered in genomics, text analysis, and medical diagnostics.