Sub topic 2
The SVM as Regularized Hinge-Loss Minimization
Assume you know vectors, dot products, hyperplanes, constrained optimization, and cross-validation. This chapter connects the SVM’s geometric margin to its optimization and kernel forms.
The SVM as regularized hinge-loss minimization
For labels y_i in {-1, +1}, the hinge loss for example i is:
max(0, 1 - y_i(w · x_i + b))
It is zero when the example is correctly classified with a margin of at least 1. The soft-margin SVM minimizes:
0.5 ||w||² + C Σ max(0, 1 - y_i(w · x_i + b))
The first term is regularization. It prefers a smaller weight vector and therefore a wider margin. The second term penalizes margin violations. C controls their relative cost.
From the primal to the dual problem
The primal form introduces slack variables ξ_i:
minimize 0.5 ||w||² + C Σ ξ_i
subject to:
y_i(w · x_i + b) >= 1 - ξ_i and ξ_i >= 0
The Lagrangian dual removes w and b as direct optimization variables. Its data-dependent term contains only dot products:
maximize Σ α_i - 0.5 ΣΣ α_i α_j y_i y_j (x_i · x_j)
with 0 <= α_i <= C and Σ α_i y_i = 0.
This change matters because dot products can be replaced by kernel evaluations.
Support vectors and what determines the boundary
A training point is a support vector when its dual coefficient αi is greater than zero. These points affect the fitted boundary. Points safely outside the margin usually have αi = 0 and do not affect it.
Points with 0 < α_i < C lie on a margin boundary. Points with α_i = C are margin violations or difficult boundary points. The decision function is a weighted combination of support-vector contributions.
The kernel trick: nonlinear boundaries without explicit features
A kernel computes an inner product in a possibly higher-dimensional feature space:
K(x_i, x_j) = φ(x_i) · φ(x_j)
The algorithm uses K directly, without constructing φ(x). A nonlinear boundary in the original space can therefore be a linear boundary in the transformed space.
Choosing a kernel
| Kernel | Useful when | Main control |
|---|---|---|
| Linear | Many features or nearly linear separation | C |
| Polynomial | Interactions of a chosen degree matter | degree, C |
| RBF | The boundary is locally shaped and unknown | C, gamma |
Start with a linear kernel for sparse, high-dimensional data. Try RBF when feature count and sample size are manageable and linear separation is inadequate.
Reading gamma in the RBF kernel
The RBF kernel is:
K(x, z) = exp(-gamma ||x - z||²)
High gamma makes each point’s influence narrow, producing flexible boundaries and possible overfitting. Low gamma spreads influence widely, producing smoother boundaries and possible underfitting. Scale features before tuning C and gamma, or distance and influence will be dominated by large-unit features.
Exercise
What usually happens when gamma is increased greatly while C remains fixed?
Show answer
The RBF boundary becomes more local and flexible, which can reduce training error but increase overfitting.