Module 6 — Support Vector Machines (Hard Margin, Soft Margin, Kernels)
Sources: Lec 13 — SVM (Hard Margin); Lec 14 — SVM (Soft Margin); Lec 15 — SVM Using Kernels.
Notation. , ; weight , bias ; hyperplane ; classifier .
C30. Hard-Margin SVM: Geometry, Margin and Support Vectors
Intuition
Many lines separate two classes. Choose the one that stays as far as possible from both classes — a fat “street” with the boundary down the middle. Safer on new data. The few points that touch the edges of the street (support vectors) alone determine the answer.
Formal definition
- Data are linearly separable iff the convex hulls of the two classes do not intersect. Convex hull of : .
- Separating hyperplane: .
- is normal to the hyperplane; distance of the hyperplane from the origin is ; distance of a point from it is .
- Rescaling freedom: leaves the hyperplane unchanged, so we fix the scale such that the closest points satisfy (setting the margin parameter ). All constraints become
- Margin .
- Support vectors: points with (exactly on the margin).
Optimisation problem
(The lecture calls the second form the “dual”; strictly it is an equivalent primal. The true dual comes in C31.)
Derivation of the margin
Take a support vector with and with . Subtract: . Projecting on the unit normal gives the width: . ∎
Key insights
- Maximising margin minimising .
- Interior points (with ) are irrelevant to the solution.
- Hard margin needs separable data (C32 relaxes this).
Worked examples
Example 1 — Very Easy
- Problem: , . Distance of from the hyperplane?
- Asked: Distance.
- Concept: Point-to-hyperplane distance.
- Approach: .
- Solution: ; . Distance .
- Final answer: .
- Key lesson: Distance is the signed value divided by .
Example 2 — Easy
- Problem: If the support vectors satisfy and , what is the margin? What gives margin ?
- Asked: Two numbers.
- Concept: Margin .
- Approach: Formula.
- Solution: . Margin .
- Final answer: ; .
- Key lesson: Big margin ⇔ small weight vector.
Example 3 — Moderate
- Problem: Positive point , negative point . Find the hard-margin hyperplane by imposing both constraints with equality and symmetry .
- Asked: , margin.
- Concept: Constraints active on both points.
- Approach: Solve for .
- Solution: : ; : . So , . , ; boundary . ; margin = distance between the two points ✓.
- Final answer: , , margin .
- Key lesson: With one point per class the optimal margin equals the distance between the points and the boundary is their perpendicular bisector.
Example 4 — Hard
- Problem: , ; positives ; negatives . Check feasibility, find the support vectors and margin.
- Asked: Verification.
- Concept: Constraints and SVs.
- Approach: Compute .
- Solution: : ✓ SV. : ✓ (not SV). : ✓ SV. : ✓. Margin .
- Final answer: Feasible; SVs ; margin .
- Key lesson: Only points with value exactly are support vectors.
Example 5 — Very Hard
- Problem: Show by the convex-hull criterion that the XOR set — positives , negatives — is not linearly separable, and that adding a point makes a separable set (e.g. positives , negatives ).
- Asked: Hull intersection.
- Concept: Hull criterion.
- Approach: Find a common convex combination.
- Solution: Positive hull contains (any ). Negative hull contains . The hulls share a point ⇒ not separable. Second set: positive hull ; negative hull : disjoint ( vs ) ⇒ separable, e.g. (, gives on all four points).
- Final answer: XOR hulls intersect at ; the second set is separable.
- Key lesson: Separability is geometric: intersecting hulls ⇒ no hyperplane.
Common mistakes
- Forgetting the in distances.
- Writing the margin as (that is one side).
Exam traps
- “Support vectors” lie on the margin; margin .
- Maximise ≡ minimise .
Connections
Perceptron (C49), logistic (C27), Lagrange dual (C31), soft margin (C32).
Mastery checklist
- Derive margin .
- Identify support vectors.
- State the hull criterion.
C31. The Lagrange Dual of the Hard-Margin SVM and the KKT Conditions
Intuition
Constrained optimisation: introduce a “price” for violating each constraint. At the optimum only constraints that are tight have nonzero price. The dual problem is over the prices , and — crucially — the data enter only through inner products (which is what makes kernels possible, C33).
Derivation
Lagrangian: Minimise over , maximise over . Substitute: and , so Dual problem: A concave quadratic program (QP); in matrix form: minimise with , , .
KKT conditions: stationarity (above), primal feasibility , dual feasibility , and complementary slackness Hence the point is on the margin (support vector); non-SVs have . from any SV : . Prediction: .
Key insights
- is a linear combination of support vectors only.
- Strong duality (convex problem): .
- Complexity depends on (size of the QP), not on .
Worked examples
Example 1 — Very Easy
- Problem: 1-D: , . Solve the dual.
- Asked: .
- Concept: Dual QP.
- Approach: .
- Solution: Gram: , others . ; . . SV : . Boundary at ; margin = distance between points ✓.
- Final answer: , , .
- Key lesson: The constraint ties the multipliers together.
Example 2 — Easy
- Problem: 2-D: , . Solve.
- Asked: .
- Concept: Dual with a Gram matrix.
- Approach: .
- Solution: Inner products: , , . . ; . . . Margin ✓.
- Final answer: each, , .
- Key lesson: Verify with the geometric answer.
Example 3 — Moderate
- Problem: Points , , with multipliers . Compute and classify and .
- Asked: , two labels.
- Concept: Recover primal from dual.
- Approach: .
- Solution: . SV : ; check with : ✓. . . . Check ✓.
- Final answer: , ; labels .
- Key lesson: Two different SVs must give the same (a consistency check).
Example 4 — Hard
- Problem: Points , , . Find the optimal and explain why one point on the margin has .
- Asked: Solution and explanation.
- Concept: Complementary slackness is one-directional.
- Approach: Primal geometry, then recover .
- Solution: Intuitively the closest approach is vertical: , . Constraints: : ; : ; : — all three on the margin. (Optimality: with the constraints force and , giving , minimal at .) Dual: . .
- Final answer: , .
- Key lesson: on the margin, but a point on the margin can still have (a “degenerate” SV); removing it does not change the solution.
Example 5 — Very Hard
- Problem: For the data of Example 3, solve the dual from scratch and verify strong duality and all KKT conditions.
- Asked: , , primal value.
- Concept: Strong duality.
- Approach: Eliminate .
- Solution: Gram entries: , , , anything with equals . . ; likewise ; . . Primal: ✓ equal ⇒ strong duality. KKT: all three constraints tight ( so ) ⇒ complementary slackness holds for every ; ✓; ✓.
- Final answer: , optimal value for both problems.
- Key lesson: Primal and dual optimal values coincide; use this as a numerical check.
Common mistakes
- Forgetting the equality constraint .
- Using with a non-support vector.
Exam traps
- The lecture’s "" is .
- The lecture says ” for support vectors and otherwise” — true except for degenerate boundary points.
Connections
C30, C32 (box constraint), C33 (kernels replace ).
Mastery checklist
- Derive the dual from the Lagrangian.
- State KKT conditions.
- Recover from .
C32. Soft-Margin SVM (Slack Variables and the Parameter )
Intuition
Real data overlap. Allow some points to be inside the street or on the wrong side, but pay a penalty proportional to how badly they violate the margin. sets the exchange rate between a wide street and violations.
Formal definition
Slack (the lecture’s notation; often ): Equivalent: (hinge loss). Meaning of : correct & outside margin; inside the margin but correctly classified (margin error); on the boundary; misclassified.
Derivation of the dual
; ; . Substituting gives the same dual as hard margin, but with the box constraint (since ). recovers the hard margin.
KKT / what means: complementary slackness and :
| Position | |||
|---|---|---|---|
| correct, outside margin (not an SV) | |||
| exactly on the margin () | |||
| inside the margin or misclassified |
All points with are support vectors (the lecture’s wording that margin-violators “are not support vectors” is non-standard). is computed from a support vector with : .
Effect of
Large ⇒ violations are expensive ⇒ narrow margin, few violations, risk of overfitting. Small ⇒ wide margin tolerant of violations, may underfit. Choose by cross-validation (C13).
Worked examples
Example 1 — Very Easy
- Problem: , . Compute for , , , , .
- Asked: Slacks and categories.
- Concept: Hinge slack.
- Approach: , .
- Solution: : , , (correct, outside margin). : , (margin error). : , , (misclassified). : , , (on margin). : , , (misclassified).
- Final answer: .
- Key lesson: ⇔ misclassified.
Example 2 — Easy
- Problem: Compute the soft-margin objective for Example 1 with .
- Asked: Value.
- Concept: .
- Approach: Sum.
- Solution: ; . Total .
- Final answer: .
- Key lesson: The penalty dominates when many points violate.
Example 3 — Moderate
- Problem: Compare candidate A: (objective part: , ) with candidate B: . Which wins for and ?
- Asked: Winner vs .
- Concept: Trade-off.
- Approach: Compute B’s slacks.
- Solution: B: . : ⇒ . : ⇒ . : ⇒ . : , ⇒ . : , ⇒ . ; . Objectives: : A , B ⇒ B. : A , B ⇒ A. Break-even: .
- Final answer: B for , A for .
- Key lesson: Large prefers fewer violations (narrower margin); small prefers a wider margin.
Example 4 — Hard
- Problem: ; labels and multipliers . (a) Check . (b) Classify each point’s status. (c) Compute and which are forced to .
- Asked: Checks and statuses.
- Concept: KKT table.
- Approach: Apply the table.
- Solution: (a) ✓. (b) Point 1: ⇒ inside margin or misclassified. Point 2: ⇒ correct, outside margin. Point 3: ⇒ on margin. Point 4: ⇒ violator. Point 5: on margin. (c) . forces for points 2, 3, 5. Support vectors: points 1,3,4,5.
- Final answer: 4 support vectors; two on the margin (3,5), two violators (1,4).
- Key lesson: The multipliers tell you where each point sits without looking at coordinates.
Example 5 — Very Hard
- Problem: 1-D: , with . Solve both the dual and the primal and show they agree. Compare with the hard margin ().
- Asked: , margin, slacks.
- Concept: Box constraint binds.
- Approach: Dual on .
- Solution: Dual: increases on ; with the maximum over is at . . Primal: with symmetry, objective with , (valid when both ): , so objective ; derivative ✓ agrees. Margin (vs hard margin). With the symmetric choice : ⇒ ; ⇒ . Both have ✓.
- Final answer: , margin , slacks each; both points are margin violators with .
- Key lesson: Small widens the margin and tolerates slack; it also makes non-unique here (any gives the same objective).
Common mistakes
- Writing for the hard-margin case.
- Forgetting that points are support vectors.
Exam traps
- Dual objective is identical to hard margin; only the constraints differ.
- ⇔ hard margin; the lecture’s “range ”.
- The lecture’s remark “larger pays more attention to points near the decision boundary” is about the same effect (fewer tolerated violations).
Connections
C30, C31, hinge loss, cross-validation (C13).
Mastery checklist
- Define slack and its four cases.
- Derive the box-constrained dual.
- Classify points from and .
C33. The Kernel Trick
Intuition
If the data are not linearly separable in the original space, lift them to a higher-dimensional space where a straight cut works. Better still, never actually go there: the dual only needs inner products, and a kernel function computes the inner product in the lifted space directly from the original coordinates.
Formal definition
Feature map (, possibly infinite). Kernel .
- Dual in feature space: , , . The dual lives in — dimension does not change.
- Prediction: , with for any .
Worked derivation: the polynomial kernel
for : This equals for (a map ): the product of corresponding entries gives each of the six terms above. In general in corresponds to a feature space of dimension . The map for a given kernel is not unique (the lecture exhibits a second ; note its printed 7-vector contains a repeated component and omits the constant, so it should be checked before use).
Key insights
- Cost of : ; cost of explicit : or infinite.
- A kernel SVM is a linear SVM in feature space, a non-linear classifier in input space.
Worked examples
Example 1 — Very Easy
- Problem: for , .
- Asked: .
- Concept: Kernel evaluation.
- Approach: Inner product first.
- Solution: ; .
- Final answer: .
- Key lesson: One inner product and a power — no feature map needed.
Example 2 — Easy
- Problem: Verify for Example 1 using .
- Asked: Same value via .
- Concept: Equivalence of kernel and feature map.
- Approach: Compute both vectors.
- Solution: ; . Products: . Sum ✓.
- Final answer: .
- Key lesson: The kernel hides a 6-D dot product.
Example 3 — Moderate
- Problem: (Lecture example) Positives ; negatives . Use if , else . Transform all points and find a separating line.
- Asked: Images and a hyperplane.
- Concept: Explicit non-linear map.
- Approach: Compute the four negative images.
- Solution: Positives have ⇒ unchanged. Negatives (norm , so the second branch): ; ; ; . Positives have ; negatives . The line separates (, ): positives give ; negatives give .
- Final answer: Separated by in the transformed space (the original space has no separating line).
- Key lesson: A well-chosen turns a non-separable set into a separable one.
Example 4 — Hard
- Problem: XOR: , , , . With solve the hard-margin dual.
- Asked: , classifier.
- Concept: Kernel SVM end-to-end.
- Approach: Build the Gram matrix; use symmetry.
- Solution: : same point ⇒ ; opposite points or : ⇒ ; all other pairs ⇒ . So , . By symmetry all ( ✓). . . Decision value at : ; at : . So with every point satisfies ✓ (all four are SVs). Classifier: . Expanding, only the cross term survives: .
- Final answer: , , (class iff ).
- Key lesson: The classic XOR problem is linearly solvable in the feature ; the kernel finds it automatically.
Example 5 — Very Hard
- Problem: (a) Feature-space dimension of for ; ; . (b) Show the Gaussian kernel’s feature space is infinite-dimensional. (c) Cost comparison for , .
- Asked: Dimensions and argument.
- Concept: Why kernels matter.
- Approach: ; Taylor series.
- Solution: (a) ; ; . (b) , and with . Each term is a polynomial kernel of degree with its own feature space; the sum over all gives infinitely many features. (c) : about multiplications + a cube; : coordinates per point.
- Final answer: , , ; Gaussian: .
- Key lesson: The trick turns an intractable (or impossible) computation into .
Common mistakes
- Computing explicitly when a kernel is available.
- Forgetting to use the kernel in prediction as well as training.
Exam traps
- Dual has variables regardless of ‘s dimension.
- ; need not be unique.
Connections
C31, C32, C34.
Mastery checklist
- Write the kernelised dual and predictor.
- Derive the quadratic-kernel feature map.
- Solve XOR with a kernel.
C34. Valid Kernels: Symmetry, Positive Semidefiniteness, Mercer; Popular Kernels
Intuition
Not every similarity function is an inner product in some space. A function qualifies only if every Gram matrix it generates is symmetric and positive semidefinite (PSD) — i.e. behaves like a matrix of dot products.
Formal conditions
- Symmetric: .
- Positive semidefinite: for every , points and scalars : , i.e. the Gram matrix is PSD (all eigenvalues ).
- Mercer’s theorem: for a symmetric with for all square-integrable , there is a space and map with . Popular kernels
- Polynomial: .
- Gaussian/RBF: , (the lecture prints , which is a typo — see Example 4).
- Sigmoid: — not PSD for all parameters.
Derivation: an explicit-feature kernel is PSD
If then . ∎
Closure properties (standard)
Sum of kernels, positive scalar multiple, and product of kernels are kernels.
Worked examples
Example 1 — Very Easy
- Problem: Is a valid kernel?
- Asked: Validity.
- Concept: Symmetry.
- Approach: Swap arguments.
- Solution: unless ⇒ not symmetric.
- Final answer: No.
- Key lesson: Check symmetry first (it is the cheapest test).
Example 2 — Easy
- Problem: Which Gram matrix can come from a kernel: or ?
- Asked: PSD test.
- Concept: Eigenvalues.
- Approach: Eigenvalues of are .
- Solution: : ⇒ not PSD (the vector gives ). : ⇒ PSD.
- Final answer: only.
- Key lesson: A negative eigenvalue disqualifies.
Example 3 — Moderate
- Problem: Prove that is PSD.
- Asked: Proof.
- Concept: Explicit feature map.
- Approach: Use the from C33.
- Solution: with ⇒ .
- Final answer: PSD.
- Key lesson: Exhibiting is the cleanest proof of validity.
Example 4 — Hard
- Problem: Points and (1-D), . Build the Gram matrix for (a) and (b) the lecture’s printed . Check PSD.
- Asked: Which is valid.
- Concept: PSD check; sign typo.
- Approach: Eigenvalues of a symmetric matrix are .
- Solution: (a) : eigenvalues ✓. (b) : eigenvalues ✗.
- Final answer: Only the negative exponent gives a valid kernel.
- Key lesson: Similarity must decrease with distance; the lecture’s printed sign is a typo.
Example 5 — Very Hard
- Problem: (a) Show the sigmoid kernel with fails PSD using points and . (b) Show closure: if are kernels then is; give a valid composite such as .
- Asked: Counter-example and closure proof.
- Concept: Mercer validity.
- Approach: Determinant of the Gram matrix.
- Solution: (a) ; ; . ⇒ one negative eigenvalue (about ) ⇒ not PSD even though . (b) ✓. The composite is a sum of the polynomial and the Gaussian kernels, both valid, hence valid.
- Final answer: Sigmoid kernel is not guaranteed valid; sums of kernels are kernels.
- Key lesson: Validity depends on parameters; verify before relying on the dual being concave.
Common mistakes
- Believing any similarity score is a kernel.
- Forgetting that the Gaussian kernel has a negative exponent.
Exam traps
- PSD must hold for all and point sets.
- RBF kernel SVM a Gaussian RBF network whose centres are the support vectors (lecture): .
Connections
C33; Gaussian-kernel bandwidth and tuned by cross-validation (C13).
Mastery checklist
- State symmetric + PSD + Mercer.
- Test PSD by eigenvalues of a Gram matrix.
- Write the Gaussian-kernel decision function.