Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Solving a huge problem two numbers at a time
The SVM dual has one weight αᵢ per training example, so 100 000 examples means a quadratic program with 100 000 variables and a 100 000 × 100 000 matrix. General QP solvers choke on that. SMO (Platt, 1998) never forms the whole problem: it picks two weights, finds their best values with a one-line formula while holding the rest fixed, updates a running gradient, and repeats. Each step is cheap; choosing which two to update decides how many steps you need.
Every time you call SVC.fit you run SMO (inside LIBSVM). Knowing how it works explains why large C or badly scaled features make training slow, why cache_size matters, and why the tol parameter trades accuracy for speed. The same coordinate-pair idea appears in many other constrained solvers.
- 1. How many multipliers does SMO change per step?
- 2. Each SMO step is solved…
- 3. In the demo, which rule needs the fewest steps?
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.One SMO step by hand
Write the dual as a minimisation: minimise ½αᵀQα − Σαᵢ with Qᵢⱼ = yᵢyⱼKᵢⱼ, 0 ≤ αᵢ ≤ C and Σαᵢyᵢ = 0. Keep the gradient G = Qα − 1 and the scores sᵢ = −yᵢGᵢ.
Why two? Changing a single αᵢ would break Σαᵢyᵢ = 0. Moving αᵢ by +yᵢλ and αⱼ by −yⱼλ keeps it, because yᵢ·yᵢλ − yⱼ·yⱼλ = 0.
Two points, linear kernel, C = 10. x₁ = (1, 0) with y₁ = +1 and x₂ = (−1, 0) with y₂ = −1.
- Start: α = (0, 0), G = (−1, −1), s = (1, −1).
- Pair: i = 1 has the largest s among points that can move up; j = 2 has the smallest among points that can move down.
- Curvature a = K₁₁ + K₂₂ − 2K₁₂ = 1 + 1 + 2 = 4. Gap s₁ − s₂ = 2. Step λ = 2/4 = 0.5, inside the box.
- New α = (0.5, 0.5). Then w = 0.5·(1, 0) + 0.5·(−1)·(−1, 0) = (1, 0).
- Gradient update: G += λ·y∘(K[:, 1] − K[:, 2]) = −1 + 0.5·2 = (0, 0). Now s = (0, 0), so the violation is 0 and SMO stops.
- Bias: b = average of sᵢ over free support vectors = 0. Margin 2/‖w‖ = 2, the distance between the points.
The steps in plain English:
- Start at α = 0, where G = −1 for every point.
- Find the most violating point i (largest s that can move up) and a partner j that can move down with sⱼ below sᵢ.
- Step λ = (sᵢ − sⱼ)/(Kᵢᵢ + Kⱼⱼ − 2Kᵢⱼ), clipped so both multipliers stay in [0, C].
- Update the two multipliers and the gradient, which costs two kernel columns.
- Stop when the largest violation max s − min s (over the movable sets) is below a tolerance; compute b from the free support vectors.
- 1. Initial gradient G at α = 0?
- 2. Step length before clipping?
- 3. One SMO step needs how many kernel columns?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.The algorithm
Movable sets.
- I_up = points where αᵢ can increase along yᵢ: (yᵢ = +1 and αᵢ below C) or (yᵢ = −1 and αᵢ above 0).
- I_low = points where it can decrease: (yᵢ = −1 and αᵢ below C) or (yᵢ = +1 and αᵢ above 0).
Optimality. α is optimal if and only if m(α) = max over I_up of sᵢ is at most M(α) = min over I_low of sᵢ. The stopping rule is m − M ≤ ε (LIBSVM’s tol, default 10⁻³).
Working-set selection.
| Rule | i | j |
|---|---|---|
| Platt’s heuristics (1998) | a KKT violator | the one with the largest error gap, or by scanning |
| Maximal violating pair (Keerthi et al., 2001) | argmax over I_up of s | argmin over I_low of s |
| Second-order (Fan, Chen and Lin, 2005; LIBSVM) | argmax over I_up of s | argmax of (sᵢ − sⱼ)²/aᵢⱼ over violating j |
The second-order rule picks the partner with the largest guaranteed objective decrease (sᵢ − sⱼ)²/(2aᵢⱼ), using the curvature aᵢⱼ = Kᵢᵢ + Kⱼⱼ − 2Kᵢⱼ.
Update. λ = (sᵢ − sⱼ)/aᵢⱼ, clipped by the box. Then αᵢ += yᵢλ, αⱼ −= yⱼλ, and G += λ·y∘(K[:, i] − K[:, j]).
Bias. b = mean of sᵢ over free SVs (αᵢ strictly between 0 and C). With none free, use (m + M)/2.
Engineering.
- A kernel cache keeps recently used columns (
cache_sizein MB). - Shrinking temporarily removes points stuck at a bound, so most steps work on a smaller problem.
- Cost per step is O(n). The number of steps grows with C and with how ill-conditioned K is.
from sklearn.svm import SVC
clf = SVC(kernel="rbf", C=10, gamma="scale", tol=1e-3, cache_size=500, shrinking=True).fit(X, y)
clf.n_iter_ # SMO iterations used- 1. SMO stops when…
- 2. Shrinking means…
- 3. The second-order rule maximises…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory
Why two-variable steps converge. The dual is a convex QP. Each SMO step solves the problem exactly in a two-dimensional feasible direction, so the objective never increases. With the maximal violating pair or the second-order rule, Keerthi and Gilbert (2002) and Chen, Fan and Lin (2006) proved convergence to an optimum. With a strictly positive definite kernel, convergence is eventually linear (Lin, 2001).
Decomposition methods. SMO is the extreme case of decomposition (Osuna et al., 1997; Joachims’ SVMlight): optimise a small working set while the rest are fixed. Larger working sets need an inner QP solver. Size two needs none, which is why SMO is simple and fast.
What makes it slow.
- Large C: more free support vectors and longer zig-zags. Exercise 2: iterations grow from 140 at C = 0.1 to 4584 at C = 100.
- Unscaled features and very large γ (an ill-conditioned K).
- n beyond about 10⁵: O(n²) kernel evaluations dominate. Use linear SVMs (dual coordinate descent, LIBLINEAR) or kernel approximations instead.
Interview questions.
- Why does SMO update two multipliers and not one? The constraint Σαᵢyᵢ = 0 fixes any single αᵢ given the others; two is the minimum that can move.
- What does
tolcontrol? The KKT violation at which SMO stops. A looser tol trains faster with a slightly less optimal dual.
- 1. SMO is a special case of…
- 2. Each SMO step makes the dual objective…
- 3. Training slows down most with…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.How much does pair selection matter?
History.
- Vapnik’s original SVM training used chunking with a general QP solver.
- Osuna, Freund and Girosi (1997) introduced decomposition; Joachims (1999) built SVMlight on it.
- Platt (1998) proposed SMO with heuristic pair selection.
- Keerthi et al. (2001) fixed its bias computation and introduced the maximal violating pair.
- Fan, Chen and Lin (2005) added second-order selection, the default in LIBSVM to this day (used by scikit-learn’s SVC).
Exercise 1. SMO matches an SLSQP solution of the dual (objective −18.873) with all three rules. It keeps Σαᵢyᵢ = 0 exactly and satisfies KKT: free SVs lie on the margin, α = 0 points lie outside it, and α = C points lie inside. Steps to a 10⁻⁵ violation: second-order 130, first-order 369, random partner 1650.
Exercise 2. Setup: ring-shaped classes, n = 300, RBF γ = 1, tolerance 10⁻³. The table shows steps to converge for each rule (cap 20 000).
| C | random partner | first-order | second-order | SVs |
|---|---|---|---|---|
| 0.1 | 416 | 140 | 140 | 278 |
| 1 | 2 522 | 441 | 257 | 154 |
| 10 | 6 954 | 1 970 | 668 | 93 |
| 100 | 20 000 (cap) | 19 322 | 4 584 | 82 |
- The ordering second-order ≤ first-order ≤ random held at every C.
- At small C the rules barely differ. Most points sit at the bound C, and the first two rules tie at 140 steps.
- At large C the gap widens sharply. Second-order needed about a quarter of first-order’s steps, and the random rule hit the cap without converging (its objective was still 1.8 above the optimum).
- Every rule slows down as C grows, even as the number of support vectors falls. Free support vectors and a flatter, more ill-conditioned dual are what cost steps.
SMO in AI, robotics and aerospace
- Every LIBSVM-based classifier, including scikit-learn’s SVC and SVR and MATLAB’s fitcsvm, trains with SMO.
- Embedded and onboard learning: SMO needs only O(n) memory per step, which suits retraining on limited hardware.
- Related ideas: coordinate descent for the lasso and linear SVMs, and block-coordinate methods in large-scale optimisation.
References
- J. C. Platt (1998). “Sequential minimal optimization: a fast algorithm for training support vector machines.” Microsoft Research Technical Report MSR-TR-98-14.
- S. S. Keerthi, S. K. Shevade, C. Bhattacharyya, K. R. K. Murthy (2001). “Improvements to Platt’s SMO algorithm for SVM classifier design.” Neural Computation 13(3).
- R.-E. Fan, P.-H. Chen, C.-J. Lin (2005). “Working set selection using second order information for training support vector machines.” JMLR 6.
- C.-C. Chang, C.-J. Lin (2011). “LIBSVM: a library for support vector machines.” ACM TIST 2(3).
- T. Joachims (1999). “Making large-scale SVM learning practical.” In Advances in Kernel Methods. MIT Press.