Previous: empirical risk and generalization · Next: kernels, Gaussian processes, and conformal prediction
Source: Lectures 13-17, pp. 47-63.
The previous part explained how controlling a class can support generalization. We now choose concrete classifiers. LDA and logistic regression can both produce linear boundaries, but they estimate different quantities. SVMs choose boundaries through their geometry.
1. Geometry of a linear classifier
Use binary labels and a score , with . Predict for and otherwise. The boundary is
If , then
Thus is perpendicular to the hyperplane. Projecting onto its unit normal gives
The two half-spaces correspond to positive and negative scores. Positive rescaling does not change the boundary or classifier:
We will use this scaling freedom to turn geometric margin maximization into a tractable optimization problem.
2. QDA and LDA from the Bayes rule
Lectures 13-14; pp. 48-51.
For classes , assume
with positive priors and positive-definite covariances. Bayes’ rule gives
The density is
Taking logarithms preserves the ordering. Dropping the common term , choose the largest score
QDA: separate covariances
Expand the quadratic form:
When depends on the class, the quadratic term remains in . The pairwise boundaries are generally quadratic: quadratic discriminant analysis.
With , estimate
These are the maximum-likelihood estimates under the model. Substitute them into to obtain the fitted classifier. The displayed inverse formulas require nonsingular estimates.
LDA: a shared covariance
Suppose every class has covariance . Then
Common terms do not affect the maximum. Therefore compare the affine scores
Their pairwise differences are linear in : linear discriminant analysis. Estimate the common covariance by pooling within-class covariances, for example the MLE
The Gaussian model explains the rule’s derivation. The resulting plug-in classifier can still be used when the true distribution is not Gaussian, but then its Bayes optimality is not guaranteed.
3. Logistic regression from conditional probabilities
Lecture 14; p. 52.
Logistic regression models directly. It does not specify a Gaussian model for .
For classes, set for and use the reference score . Define
The shared denominator cancels in an argmax. Exponentiation preserves order, so
Thus pairwise decision boundaries are affine despite the nonlinear probabilities.
Fit by maximum likelihood
For independent labeled observations, maximize the conditional likelihood . Taking logs and changing the sign gives
where . This is empirical minimization of negative log-likelihood.
For binary labels and one score ,
so the objective becomes
A large positive signed score means a confident correct prediction and a small loss. A negative signed score receives a larger penalty.
4. From perceptron motivation to maximum margin
Lectures 14-15; pp. 52-55.
The PDF motivates the perceptron by penalizing distances of wrongly classified observations to the boundary. For , wrong-side distances can be written as
This motivates correcting wrong-side points, but does not distinguish all the separators of a separable dataset. It also gives no positive margin requirement.
Assume both classes occur and the data are strictly linearly separable:
for some . Strict positivity matters; classification by a tie convention at score zero does not ensure a positive margin.
Derive the hard-margin problem
The margin of a separating hyperplane is its smallest training-point distance:
Let . Rescale by . The classifier is unchanged and its minimum signed score becomes 1. For the rescaled parameters,
Maximizing is equivalent to minimizing . Hence the hard-margin SVM solves
The objective is convex and the constraints are affine. At an optimum, the minimum signed score is 1: otherwise scaling both parameters down would preserve feasibility and reduce the objective.
The distance from the decision boundary to the nearest observations is ; the distance between the two supporting hyperplanes is .
5. Convex duality and KKT
Lecture 15; pp. 55-56.
Consider a differentiable convex objective and differentiable convex constraints :
Introduce multipliers and the Lagrangian
Define the dual function and maximize it over .
Why the dual gives a lower bound
For any feasible and ,
Thus the best dual value cannot exceed the best primal value: weak duality.
The primal can also be written as . For feasible , the inner supremum equals ; if any constraint is violated, its multiplier can grow without bound. The dual reverses the optimization order. Strong duality means the optimal values coincide.
Slater and the KKT conditions
Slater’s condition asks for a strictly feasible point with for every inequality. Under the stated convex setting and an attained finite optimum, it ensures the usual strong-duality and multiplier-existence result.
The Karush-Kuhn-Tucker conditions are
To see sufficiency, stationarity minimizes the convex function , so . Complementary slackness makes this equal . Weak duality then shows both points are optimal.
For strictly separable SVM data, scale a separator until every signed score is strictly greater than 1. This supplies Slater’s point.
6. Derive the hard-margin SVM dual
Lectures 15-16; pp. 56-60.
The constraints are . Therefore
First minimize over the intercept
If , letting move in the appropriate direction drives the Lagrangian to . A finite dual value thus requires
Under this constraint, the intercept term vanishes.
Then minimize over the weight vector
Set its gradient to zero:
Writing , the terms at the minimum are . Hence
The dual is
The matrix is positive semidefinite, since
The dual objective is therefore concave.
Recover the primal solution
Stationarity gives . Complementary slackness gives
If , the constraint is tight. Since ,
Such an index exists when both classes are present: if every multiplier were zero, stationarity would give , and one intercept could not meet the constraints for both signs.
Support vectors and perturbations
Points with positive multipliers contribute to and lie on the hard margin. The PDF calls every margin point a support vector; in a degenerate solution a margin point may have multiplier zero, so the reverse implication need not hold.
Suppose a point lies strictly outside the margin on the correct side. Its multiplier is zero. Move it while keeping the old separator feasible. The original weights, intercept, and multipliers still satisfy KKT:
- Its zero multiplier leaves stationarity unchanged.
- Feasibility holds by the condition on its new location.
- Its complementary-slackness product remains zero.
- The other constraints and multipliers are unchanged.
Therefore the original solution remains optimal. This explains the limited sensitivity to observations that do not determine the margin.
Dimensions and inner products
The primal optimizes parameters; the dual optimizes multipliers. Training and prediction depend on inputs only through inner products:
This can be useful when is large, although dual computation also depends on the cost of forming and storing the Gram matrix.
7. Soft margins and hinge loss
Lecture 17; p. 61.
Hard-margin constraints are infeasible for nonseparable data. Introduce slack variables:
For fixed , each constraint requires both and . Since , the smallest feasible slack is optimal:
Substituting gives the equivalent unconstrained objective
This is regularization plus hinge loss. A correctly classified observation can still incur loss when its signed score is between 0 and 1.
Larger penalizes violations more strongly; smaller puts more emphasis on a small norm. The hard-margin limit as grows requires separable data.
The corresponding dual constraint
To continue the earlier derivation, add multipliers for . The coefficient of in the Lagrangian is . Minimization requires it to vanish:
The other stationarity equations are unchanged. Thus the same dual objective now has box constraints and .
If , then forces , and complementary slackness gives . Such points can recover the intercept. A soft-margin support vector with may lie inside the margin or be misclassified.
Choose the tuning parameter
Fit the model for each candidate on training data. Evaluate its classification error on a separate validation set and choose the value with the smallest validation error. Cross-validation repeats this fit-and-evaluate procedure over folds. Keep final test data separate from tuning.
8. Nonlinear geometry and the kernel trick
Lecture 17; pp. 61-63.
A linear boundary cannot separate every useful geometry. For points in inner and outer rings in , the map
adds squared radius as a coordinate. A plane in this feature space can separate radii that no line in the original plane can separate.
For a general feature map , the hard-margin problem becomes
The same stationarity calculation gives
Thus the dual uses only . Define
Replace every original inner product by . Prediction becomes
For a hard-margin point with positive multiplier,
This rule is linear in the feature space and can be nonlinear in the original inputs. We can compute it without explicitly constructing .
The next question is which functions really behave as feature-space inner products. That leads to kernels and RKHS: continue to Part 4.