Sub topic 8
Support vectors and what determines the boundary
This chapter assumes you know the hard-margin and soft-margin SVM problems and have seen the dual formulation. It also assumes basic NumPy and scikit-learn.
What a support vector is
In the dual problem, each training point gets a multiplier α_i ≥ 0. The KKT complementary slackness conditions tie each multiplier to the point's margin:
- αi = 0: the point satisfies yi(w·x_i + b) > 1. It lies outside the margin and has no effect on the solution.
- 0 < αi < C: the point lies exactly on the margin, with yi(w·x_i + b) = 1.
- αi = C: the point is inside the margin or misclassified, with slack ξi > 0.
Support vectors are the points with α_i > 0. The weight vector is a sum over them only:
w = Σ αi yi x_i
So you can delete every non-support vector, refit, and get the same boundary.
Inspecting them in scikit-learn
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)
clf = SVC(kernel="linear", C=1.0).fit(X, y)
print("support vectors per class:", clf.n_support_)
print("indices:", clf.support_)
# dual_coef_ holds alpha_i * y_i for each support vector
w_from_dual = clf.dual_coef_ @ clf.support_vectors_
print("w from dual:", w_from_dual, "coef_:", clf.coef_)
# Refit on the support vectors alone
clf2 = SVC(kernel="linear", C=1.0).fit(X[clf.support_], y[clf.support_])
print("same w:", np.allclose(clf2.coef_, clf.coef_, atol=1e-3))dual_coef_ stores αi·yi, so its absolute values are capped at C. The first check confirms that w is rebuilt from support vectors. The second shows that the refit on those points gives the same boundary, up to solver tolerance.
Consequences
- Sparsity. Prediction uses only the support vectors: f(x) = Σ αi yi K(x_i, x) + b. Fewer support vectors means faster prediction and a smaller model.
- Robustness to far-away points. Moving or adding a point outside the margin changes nothing. Moving a support vector shifts the boundary.
- Effect of C. A small C allows many points to reach α_i = C, so the support vector count is large. A large C punishes slack, which usually reduces the margin and changes which points are support vectors.
- Generalization signal. A high fraction of support vectors, close to the training set size, suggests the model is memorizing. This often happens with a very large gamma in the RBF kernel.
Common errors
- Reading
coef_with a nonlinear kernel.coef_exists only forkernel="linear". For other kernels, w lives in an implicit feature space, so usedual_coef_andsupport_vectors_. - Assuming support vectors sit exactly on the margin. Only points with 0 < αi < C do. Points with αi = C are inside it or on the wrong side.
- Comparing to a tolerance of zero. The solver stops at a tolerance (
tol), so margins are only approximately 1.
Exercise
You fit an SVC and clf.n_support_ is [48, 49] on a training set of 100 points. What does this suggest, and which hyperparameter would you check first?
Show answer
Almost every point is a support vector, so the boundary depends on nearly all the data. Either C is very small, so many points hit the bound α_i = C, or, with an RBF kernel, gamma is so large that the model memorizes the training set. Check C and gamma first, and compare cross-validated scores across values.