Sub topic 8
Support vectors and what determines the boundary
This chapter assumes you know the soft-margin primal problem (margin term plus C times the slack), the role of C, and the basic idea of a Lagrangian with multipliers. It uses those to explain which training points the fitted boundary actually depends on.
The boundary is built from a few points
After the dual derivation, the weight vector of a linear SVM has this form:
w = sum over i of alpha_i * y_i * x_i
Here alpha_i is the Lagrange multiplier for the constraint on training point i, and y_i is its label in {-1, +1}. Every alpha_i satisfies 0 <= alpha_i <= C. The dual also requires sum alpha_i * y_i = 0.
Most alpha_i are exactly zero. A point with alpha_i = 0 adds nothing to w. A support vector is a training point with alpha_i > 0. Only these points shape the hyperplane. You can delete every other point and refit, and you get the same boundary.
What the KKT conditions say
The Karush-Kuhn-Tucker (KKT) conditions hold at the optimum. For the soft-margin problem, the key one is complementary slackness. For each point, either its multiplier is zero or its constraint is tight:
alpha_i * (y_i * (w·x_i + b) - 1 + xi_i) = 0(C - alpha_i) * xi_i = 0
Here xi_i is the slack of point i. Write f(x) = w·x + b. These conditions split the training points into three groups.
| Multiplier | Slack | Position | Role |
|---|---|---|---|
| `alpha_i = 0` | `xi_i = 0` | `y_i f(x_i) >= 1`, on the correct side and outside or on the margin | Not a support vector. No influence. |
| `0 < alpha_i < C` | `xi_i = 0` | `y_i f(x_i) = 1`, exactly on the margin | Free support vector. |
| `alpha_i = C` | `xi_i >= 0` | `y_i f(x_i) <= 1`, inside the margin or misclassified | Bounded support vector. |
Free support vectors are the only points that pin down the intercept. Solving y_i (w·x_i + b) = 1 for any free point gives b = y_i - w·x_i. Solvers usually average this over all free points for numerical stability.
Checking this in scikit-learn
SVC stores the dual solution in these attributes:
support_: indices of the support vectors in the training set.support_vectors_: the support vectors themselves.n_support_: the count per class.dual_coef_: the productsalpha_i * y_ifor the support vectors only.
The following script rebuilds w from the dual coefficients, then refits on the support vectors alone and compares the two boundaries.
import numpy as np
from sklearn.datasets import make_blobs
from sklearn.svm import SVC
X, y = make_blobs(n_samples=100, centers=2, cluster_std=1.2, random_state=0)
C = 1.0
clf = SVC(kernel="linear", C=C, tol=1e-8).fit(X, y)
# Rebuild w = sum alpha_i * y_i * x_i from the dual solution
w_from_dual = clf.dual_coef_ @ clf.support_vectors_
print("w matches coef_:", np.allclose(w_from_dual, clf.coef_))
# Refit using only the support vectors
sv_idx = clf.support_
clf_sv = SVC(kernel="linear", C=C, tol=1e-8).fit(X[sv_idx], y[sv_idx])
print("support vectors kept:", len(sv_idx), "of", len(X))
print("max |w difference|:", np.abs(clf.coef_ - clf_sv.coef_).max())
print("|b difference|:", abs(clf.intercept_[0] - clf_sv.intercept_[0]))The two differences should be tiny, on the order of solver tolerance. The refit gives the same boundary because all the discarded points had alpha = 0.
Telling free from bounded support vectors
You can separate the two kinds by checking which multipliers sit at the upper limit C. Free vectors should also have a signed score of about 1.
import numpy as np
from sklearn.datasets import make_blobs
from sklearn.svm import SVC
X, y = make_blobs(n_samples=100, centers=2, cluster_std=2.5, random_state=1)
C = 0.5
clf = SVC(kernel="linear", C=C, tol=1e-8).fit(X, y)
y_signed = 2 * y - 1 # classes 0/1 -> -1/+1
alpha = np.abs(clf.dual_coef_.ravel())
bounded = np.isclose(alpha, C)
free = ~bounded
scores = y_signed[clf.support_] * clf.decision_function(X[clf.support_])
print("free:", free.sum(), "bounded:", bounded.sum())
print("free y*f values:", np.round(scores[free], 3))
print("bounded y*f max:", np.round(scores[bounded].max(), 3))Free vectors print values near 1.0. Bounded vectors have y*f <= 1, so their maximum is at most 1 up to tolerance. Points with y*f < 0 are misclassified training points, and they are always bounded.
What changes the number of support vectors
The support-vector count tells you how hard the problem is for your settings.
- Small C allows wide margins with many violations, so many points become bounded support vectors. The model is smooth and the fraction of support vectors is high.
- Large C punishes violations, so the margin narrows and the model fits the training data tightly. Fewer points may be bounded, but the solution is more sensitive to individual points.
- Large gamma in an RBF kernel makes each point's influence very local. Nearly every point can end up as a support vector, which is a sign of overfitting.
- Overlapping classes produce many bounded support vectors regardless of the kernel.
A rough rule of thumb is that the leave-one-out error is at most the fraction of points that are support vectors. A fraction close to 1 means the model has found little structure to compress.
Consequences and edge cases
Sparsity at prediction time. The decision function is f(x) = sum over support vectors of alpha_i * y_i * K(x_i, x) + b. Prediction cost grows with the number of support vectors, not with the training set size. With a linear kernel you can collapse the sum into one w, and coef_ does this for you. With a nonlinear kernel you must keep all support vectors.
Robustness is partial. Moving or deleting a non-support point leaves the boundary unchanged only while that point stays on the correct side of the margin. If it moves inside the margin, it becomes a support vector and the boundary shifts. Bounded support vectors, including mislabeled points, always pull on the solution. Their pull is capped, because alpha_i <= C limits each point's weight.
Duplicates and ties. If two identical points are both support vectors, the solver may split the multiplier between them in different ways. The boundary is unique for the strictly convex primal, but the individual alpha_i values need not be.
Numerical tolerance. The solver stops when KKT conditions hold within tol (default 1e-3). Points very near the margin may or may not be reported as support vectors. Use np.isclose rather than exact comparisons, as in the example above.
Multiclass. SVC trains one binary problem per pair of classes, so dual_coef_ has one row per class minus one and the support vectors are shared across the sub-problems. Reading alpha values from it is more involved than in the binary case.
Exercise
You train a linear SVC with C=1 and find that 8 of 200 points have 0 < alpha < 1, and 12 have alpha = 1. You then delete 100 points that had alpha = 0 and refit with the same settings. What happens to the boundary, and which points would you use to recompute b?
Show answer
The boundary stays the same, up to solver tolerance, because points with alpha = 0 contribute nothing to w = sum alphai yi xi and their constraints were inactive. Use the 8 free support vectors (0 < alpha < C) to recompute b, since they lie exactly on the margin and satisfy yi (w·xi + b) = 1, so b = yi - w·x_i. The 12 bounded points have slack and do not satisfy that equality.
Exercise
Why does using a very large gamma with an RBF kernel tend to produce a model where almost every training point is a support vector?
Show answer
A large gamma makes each kernel value decay quickly with distance, so a point only influences predictions very close to it. To fit the training labels, the model needs a nonzero alpha at almost every point, so almost every point becomes a support vector. The model then memorizes the training set and overfits, and prediction becomes slow because it sums over nearly all training points.