Skip to content
mlmentorship

SVM and the kernel trick

Solve a margin classifier, price violations, and change the feature space without confusing a score with a probability.

Published · 6 min read ·Core ·Foundation
Reading depth

An SVM chooses a decision boundary by balancing its norm against small signed margins.

Summary

Let negative examples be and positive examples be . Which linear score separates them with the widest normalized margin? Use labels and predict the sign of the score, with an explicit tie policy at zero. The figure illustrates a soft-margin fit; its three highlighted points are not this four-point dataset.

Learning objective

Only nonzero dual weights contribute to the SVM decision sum

Zero dual weight means no contribution to the decision sumOnly support vectors with nonzero alpha enter the weighted kernel decision. Other training examples still exist but add zero here.All examples remain; only nonzeroweights contribute10.72030.440sumExamples two and four add zero, notmissing data.
Derivation
Support vectors on or inside two SVM margin rails A vertical decision boundary lies between dashed negative-one and positive-one margin rails. Negative-class circles appear on the left and positive-class diamonds on the right. Three points on or inside the rails have prominent outer rings and labels saying alpha i is greater than zero, so they are support vectors. Four correctly classified points beyond the rails have no rings and labels saying alpha i equals zero. A note states that prediction sums only over the three ringed support vectors. CLASS −1 · CIRCLES CLASS +1 · DIAMONDS f(x) = −1 f(x) = 0 f(x) = +1 beyond margin αᵢ = 0 on rail · αᵢ > 0 on rail · αᵢ > 0 inside · αᵢ > 0 beyond margin αᵢ = 0 decision(x) = sign(Σᵢ∈SV αᵢ yᵢ K(xᵢ, x) + b) prediction sums over the 3 ringed points only
compare each point with its class-margin rail. The three rings identify positive dual coefficients in this schematic fit. Strictly outside the margin, coefficients are zero. A point on a rail can also have zero coefficient in a degenerate solution. Soft margin permits positive coefficients inside the rails. Sources: Burges's tutorial and the SVM formulation.
Check: Which displayed points actually contribute to the decision sum? Why is lying on a margin alone not a universal proof of nonzero alpha?
Read it this way: Only support vectors with nonzero alpha enter the weighted kernel decision. Other training examples still exist but add zero here.
Does a zero dual contribution delete the corresponding training observation?

The hard-margin SVM (separable case)

Normalize the nearest signed scores to at least one:

The examples at and require and . Adding gives . Thus achieves the minimum objective . Signed margins are ; the rails are at and , with width . Without score normalization, multiplying both parameters changes no boundary and makes raw score gaps meaningless.

The soft-margin SVM (non-separable)

Change the requirement: price violations instead of forbidding them. For , minimize

The separating fit costs ; the constant-zero score costs . At , zero beats that separator: . Neither comparison proves that zero is optimal. The optimum is , with objective . Coefficients satisfy the dual constraints and achieve the same objective. All four points now support the fit; retaining the hard-margin coefficients would violate their new upper bound. Slack is , not necessarily a misclassification. A correctly classified score still pays .

The dual formulation and the kernel trick

The soft-margin dual is

For hard margin, remove the upper bound on . In the four-point example, coefficients reconstruct . Their dual objective is , matching the primal and certifying optimality.

Change the requirement: use an RBF kernel on only , with labels and . Set and . The cross-similarity is ; diagonal entries are one. The equality constraint makes both coefficients . Their dual is , maximized at within . With , both signed scores equal . Doubling makes cross-similarity and changes the optimum to . Do not reuse the old coefficients after changing kernel geometry. Use symmetric positive-semidefinite kernels; an arbitrary similarity need not yield a convex dual.

Support vectors

Prediction uses . Zero coefficients remove terms from this fitted score, not a guarantee about arbitrary retraining or preprocessing changes. For a soft-margin optimum, implies a point lies on its rail. Points with can lie on or inside it.

Reconstruct: does a large positive score mean a calibrated probability? No: margin optimization supplies no probability normalization or calibration guarantee.

When to use SVMs in 2026

Compare a scaled linear SVM, an RBF SVM and task-appropriate alternatives under the same validation protocol. A dense Gram matrix stores entries; solver cost depends on the implementation and data. Linear solvers need not materialize that matrix. Kernel prediction evaluates one term per retained support vector, so measure deployment cost too.

Common pitfalls

Scale features using training-only statistics and tune interacting parameters inside validation folds. For , changing units changes similarities unless changes appropriately. Hinge loss is not log loss, and sigmoid similarities are not PSD for arbitrary parameters. The primal is strictly convex in , not jointly strictly convex in the unregularized intercept. For example, opposite labels at the same zero input admit every when .