Session 2: Overfitting, Regularization, Margins & Kernel Methods
2026-09-28
8:30–11:30 · 180 min
| Time | Block |
|---|---|
| 8:30–8:35 | Recap: linear regression |
| 8:35–9:00 | GLM: polynomial & periodic maps |
| 9:00–9:30 | Regularization: Ridge & LASSO |
| 9:30–9:50 | Structural Risk Minimization: shattering, VC dim & bound |
| 9:50–10:00 | ⚡ Exercises: VC dim |
| 10:00–10:10 | ☕ Break |
| 10:10–10:40 | SVM, support vectors |
| 10:40–11:00 | Kernel SVM: kernel trick, popular kernels, SDCA |
| 11:00–11:10 | Representer theorems & RKHS |
| 11:10–11:20 | Kernel approximations: RFF & Nyström |
| 11:20–11:25 | Kernel PCA |
| 11:25–11:30 | Wrap-up |
0:05–0:30 · 25 min
What if the linear classifier \(\langle w, x \rangle\) is not enough?
\[ \phi: x \mapsto [x, x^2, \ldots, x^p], \qquad h(x) = \langle w, \phi(x) \rangle \]
Fitting the same noisy cubic with \(p=1,2,3,5,7\). \(p=3\) is the truth. Watch the extra powers (\(\times\) = true coefficient).
Same 25-point dataset. True cubic is dashed.
\[ x^{\otimes p} = x \otimes \cdots \otimes x \quad (p \text{ times}), \qquad \langle a\otimes a',\, b\otimes b'\rangle = \langle a,b\rangle\langle a',b'\rangle \]
\[ \phi: x \mapsto [\sin(f_0 x), \sin(2f_0 x), \dots, \sin(p f_0 x)] \]
\[ \phi: x \mapsto [\sin(\omega_1^\top x), \dots, \sin(\omega_p^\top x)], \qquad \omega_i \sim \mathcal{N}(0,\sigma) \]
\[ \sin(a)\sin(b) = \tfrac12[\cos(a-b) - \cos(a+b)] \] \[ \langle \phi(x), \phi(x') \rangle = \frac12\sum_{i=1}^p \big[\cos(\omega_i^\top(x-x')) - \cos(\omega_i^\top(x+x'))\big] \]
True signal \(\sin(2x) + 0.35\sin(10x)\) (dashed). With too many frequencies, it starts memorizing noise instead of signal.
As usual, training error cannot be trusted for selecting hyper-parameters
5-fold CV on the true degree-3 cubic. Training error keeps dropping. Validation bottoms out near the truth, then rises.
Occam’s razor: pick the lowest degree that has good validation error
0:30–1:00 · 30 min
\(\Omega(w)\) grows with the complexity of \(w\). Two popular choices:
Prevent parameters from blowing up:
\[ \mathcal{L}(w) = \frac1n\sum_i \ell(x_i^\top w, y_i) + \lambda\|w\|^2 \]
Bonus: Fixes the pseudo-inverse’s instability when \(X^\top X\) has small eigenvalues (e.g., \(\mathrm{rank}(X) < d\))
Setting the derivative of the augmented risk to \(0\): \[ \frac{\partial \mathcal{L}}{\partial w} = 0 = \frac{2}{n}\big(X^\top X w - X^\top Y\big) + 2\lambda w \]
Closed form. \(\displaystyle w = (X^\top X + n\lambda I)^{-1} X^\top Y\).
Assume some parameters are harmful and should be \(0\):
\[ \mathcal{L}_\Omega(w) = \frac1n \sum_i \ell(w^\top x_i, y_i) + \lambda \|w\|_1 \]
To see why \(\ell_1\) gives sparsity, project \(X\) onto its own eigenspace via SVD, \(X = VSU^\top\): \[ \mathcal{L}(w) = \|Y - XUw\|^2 + \lambda\|w\|_1 = \|Y - VSw\|^2 + \lambda\|w\|_1 \] (using \(U^\top U = I\))
\[ \frac{\partial \mathcal{L}}{\partial w} = 0 = -2SV^\top Y + 2S^2 w + \lambda\, \mathrm{sign}(w) \]
\[ \Rightarrow \quad w = S^{-1}V^\top Y - S^{-2}\,\frac{\lambda\,\mathrm{sign}(w)}{2} \]
Let \(\tilde{w} = S^{-1}V^\top Y\); note \(\mathrm{sign}(w) = \mathrm{sign}(\tilde w)\).
If \(\mathrm{sign}(w_i) = \mathrm{sign}(\tilde w_i) = +1\): \[ w_i = \underbrace{\tilde w_i}_{>0}\left(1 - \frac{\lambda S_i^{-2}}{2|\tilde w_i|}\right) > 0 \]
which only makes sense if the parenthesis is positive, i.e. \[ w_i = \tilde w_i \max\left(0,\ 1 - \frac{\lambda S_i^{-2}}{2|\tilde w_i|}\right) \]
The case \(\mathrm{sign} = -1\) gives the identical formula by symmetry.
Soft thresholding. \[ w_i = \tilde{w}_i \max\left(0,\ 1 - \frac{\lambda S_i^{-2}}{2|\tilde{w}_i|}\right), \qquad \tilde{w} = S^{-1}V^\top Y \]
Why not combine both?
\[ \mathcal{L}_\Omega(w) = \frac1n \sum_i \ell(w^\top x_i, y_i) + \lambda_1 \|w\|_1 + \lambda_2 \|w\|_2^2 \]
\(\lambda_1\) and \(\lambda_2\) chosen by cross-validation
1:00–1:20 · 20 min
Among predictors with equal (zero) empirical risk, prefer the simplest one.
Can we prove it’s a good one?
For binary classification with \(y \in \{-1,1\}\), a dataset of size \(m\) has \(2^m\) possible labelings.
Shattering coefficient. \(\displaystyle m_{\mathcal{H}} = \sup_{|\mathcal{A}|=m} \hat{m}_{\mathcal{H}}(\mathcal{A})\), the largest number of distinct labelings \(\mathcal{H}\) can realize on any dataset of size \(m\).
Risk Upper Bound using Shattering. With probability \(\geq 1-\delta\) over the choice of \(\mathcal{A}\) of size \(m\), for any \(h \in \mathcal{H}\): \[ \mathcal{R}(h) \leq \hat{\mathcal{R}}_{\mathcal{A}}(h) + \sqrt{\frac{8}{m}\left(\ln \mathbb{E}[\hat{m}_{\mathcal{H}}(\mathcal{A}_{2m})] - \ln\frac{\delta}{4}\right)} \]
with \(\mathcal{A}_{2m}\) an independent auxiliary dataset of size \(2m\).
Symmetrization. For \(n\varepsilon^2 \geq 2\), \[ P\Big(\sup_{h}(\mathcal{R}(h)-\hat{\mathcal{R}}_n(h)) > \varepsilon\Big) \leq 2P\Big(\sup_h(\hat{\mathcal{R}}_{1:n}(h) - \hat{\mathcal{R}}_{n+1:2n}(h)) > \varepsilon/2\Big) \]
VC dimension. The largest \(m_{\mathrm{VC}}\) such that \(\mathcal{G}_{\mathcal{H}}(m_{\mathrm{VC}}) = m_{\mathrm{VC}} \ln 2\) (i.e. \(\mathcal{H}\) shatters some set of that size), or \(\infty\) if none exists.
Named after Vapnik and Chervonenkis who developped the theory in the 60s
For finite VC dimension, one can show \(\mathcal{G}_{\mathcal{H}}(m) \leq m_{\mathrm{VC}}(\ln \frac{m}{m_{\mathrm{VC}}}+1)\) for \(m > m_{\mathrm{VC}}\).
Corollary. With probability \(\geq 1-\delta\), \[ \mathcal{R}(h) \leq \hat{\mathcal{R}}_{\mathcal{A}}(h) + \sqrt{\frac{8}{m}\left(m_{\mathrm{VC}}\left(\ln\frac{2m}{m_{\mathrm{VC}}}+1\right) - \ln\frac{\delta}{4}\right)} \]
1:20–1:30 · 10 min
What is the VC dimension of linear classifiers in 2D?
Try all possible labeling exhaustively
What is the VC dimension of axis-aligned rectangles?
1:30–1:40 · 10 min
Back at 10:10 to switch gears: from regression to classification, the theory of why margins matter, and Support Vector Machines.
1:40–2:10 · 30 min
VC dimension of linear predictors in \(\mathbb{R}^d\) is \(d+1\): no generalization guarantee below \(d+1\) training samples.
For \(h(x) = w^\top x + b\), the decision boundary is the hyperplane orthogonal to \(w\): \[ \Delta = \min_{x_i \in \mathcal{A}} \frac{|w^\top x_i + b|}{\|w\|} \]
Solid line: decision boundary \(w^\top x+b=0\). Dashed lines: margin boundaries \(w^\top x+b=\pm1\).
Fix \(\Delta=1\) (conveniently, where the hinge loss becomes zero) and minimize \(\|w\|\) under that constraint: \[ \min_{w,b} \frac12\|w\|^2 \quad \text{s.t.}\quad \forall i,\ y_i(w^\top x_i+b) \geq 1 \]
Cortes & Vapnik: allow constraint violations \(\zeta_i \geq 0\): \[ \min_{w,b,\zeta}\ \frac{\lambda}{2}\|w\|^2 + \frac1n\sum_i \zeta_i \quad \text{s.t.}\quad y_i(w^\top x_i+b) \geq 1-\zeta_i,\ \zeta_i\geq 0 \]
The soft-margin problem is equivalent to an unconstrained problem with the hinge loss: \[ \min_{w,b}\ \frac{\lambda}{2}\|w\|^2 + \frac1n \sum_i \max\big(0,\ 1-y_i(w^\top x_i+b)\big) \]
SGD for the hinge loss. \(w \leftarrow 0,\ b \leftarrow 0\); repeat: sample \(i\) uniformly, then \[ \nabla_w = \lambda w - \mathbb{1}[y_i(w^\top x_i+b) < 1]\, y_i x_i, \qquad \nabla_b = -\mathbb{1}[y_i(w^\top x_i+b) < 1]\, y_i \] \[ w \leftarrow w - \eta\, \nabla_w, \qquad b \leftarrow b - \eta\, \nabla_b \]
Back to the hard-margin problem. Its Lagrangian, with \(\alpha_i \geq 0\): \[ \mathcal{L}(w,b,\alpha) = \frac12\|w\|^2 - \sum_{i=1}^n \alpha_i\big(y_i(w^\top x_i+b)-1\big) \]
Set the derivative with respect to \(w\) to zero at the optimum: \[ \frac{\partial \mathcal{L}}{\partial w}(w^\star) = w^\star - \sum_i \alpha_i y_i x_i = 0 \]
\[ \Rightarrow\quad w^\star = \sum_{i=1}^n \alpha_i y_i x_i \]
KKT’s complementary slackness condition: \(\forall i,\ \alpha_i\big(y_i(w^{\star\top}x_i+b)-1\big) = 0\).
\[ \Rightarrow\quad y_i(w^{\star\top}x_i + b) \neq 1 \ \Rightarrow\ \alpha_i = 0 \]
SVM has support vectors. Only points exactly on the margin (\(y_i(w^{\star\top}x_i+b)=1\)) can have \(\alpha_i > 0\).
Degree-3 polynomial features before linear classification.
2:10–2:30 · 20 min
The dual problem re-expresses everything in terms of \(\alpha\) only: \[ \max_\alpha \inf_{w,b} \mathcal{L}(w,b,\alpha), \quad \text{s.t.}\ \alpha_i\geq 0 \]
\[ \inf_{w,b}\mathcal{L}(w,b,\alpha) = \sum_i \alpha_i - \frac12 \sum_{i,j}\alpha_i\alpha_j y_i y_j\, x_i^\top x_j \]
Dual SVM problem. \[ \max_\alpha\ \sum_i \alpha_i - \frac12\sum_{i,j}\alpha_i\alpha_j y_i y_j\, x_i^\top x_j \]
Since the dual only needs inner products, we can map to a higher-dimensional space \(\phi(x)\) without ever computing \(\phi\) explicitly.
Kernel. \(k(x,x') = \langle \phi(x), \phi(x') \rangle\) for some (possibly implicit, possibly infinite-dimensional) \(\phi\). Symmetric and positive semi-definite: \(\sum_{ij}\alpha_i\alpha_j k(x_i,x_j) \geq 0\).
Soft-margin dual with a kernel (\(C = 1/(n\lambda)\)): \[ \max_\alpha\ \sum_i \alpha_i - \frac12\sum_{i,j}\alpha_i\alpha_j y_i y_j\, k(x_i,x_j) \quad \text{s.t.}\ 0\leq \alpha_i \leq C,\ \sum_i \alpha_i y_i = 0 \]
Decision function: \[ h(x) = \sum_{i=1}^n \alpha_i y_i\, k(x,x_i) + b \]
Kernel combinations. If \(k_1,k_2\) are kernels and \(\alpha\geq 0\), then
are all kernels.
What is the VC dimension of a kernel SVM with a Gaussian kernel?
\[ k(x_i, x_j) = e^{-\gamma\|x_i - x_j\|^2} \]
Stochastic Dual Coordinate Ascent. \(\alpha \leftarrow 0\); repeat:
Gaussian kernel SVM solved with SDCA
2:30–2:40 · 10 min
RKHS. A Hilbert space \(\mathcal{H}\) of functions \(h: \mathcal{X} \to \mathbb{R}\), equipped with a kernel \(k(\cdot,\cdot)\), such that pointwise evaluation is an inner product with a specific element \(\phi_x \in \mathcal{H}\): \[ h(x) = \langle h, \phi_x \rangle, \qquad \langle \phi_x, \phi_{x'} \rangle = k(x,x') \]
Let \(\mathcal{A} = \{(x_i,y_i)\}\), \(\ell(\cdot,\cdot)\) any error measure, \(g\) any strictly increasing function. Any minimizer of \[ w^\star = \arg\min_w \frac1n \sum_i \ell(y_i, \langle w, x_i \rangle) + g(\|w\|) \] admits a decomposition \(\displaystyle w^\star = \sum_{i=1}^n \alpha_i x_i\).
Split \(w^\star\) into the part spanned by the data and an orthogonal residual: \[ w^\star = w_{\mathcal{A}} + w_\perp = \sum_{i=1}^n \alpha_i x_i + w_\perp \]
The same argument goes through in a general RKHS, replacing \(x_i\) with \(\phi_{x_i} = k(x_i, \cdot)\):
Any minimizer \(h^\star \in \mathcal{H}\) of \[ h^\star = \arg\min_{h\in\mathcal{H}} \frac1n\sum_i \ell(y_i, h(x_i)) + g(\|h\|_{\mathcal{H}}) \] admits a decomposition \(\displaystyle h^\star = \sum_{i=1}^n \alpha_i\, k(x_i, \cdot)\).
2:40–2:50 · 10 min
For shift-invariant kernels (like the Gaussian kernel): \[ \phi(x) = \frac{1}{\sqrt{D}}\big[\cos(\omega_1^\top x), \sin(\omega_1^\top x), \dots, \cos(\omega_D^\top x), \sin(\omega_D^\top x)\big] \] with \(\omega_1,\dots,\omega_D \sim \mathcal{N}(0,\sigma^2 I)\) random and fixed in advance.
Using \(\cos(a-b) = \cos(a)\cos(b)+\sin(a)\sin(b)\): \[ \langle \phi(x),\phi(x')\rangle = \frac1D \sum_{k=1}^D \cos\big(\omega_k^\top(x-x')\big) \]
Instead of approximating the kernel function, approximate the Gram matrix directly via a low-rank decomposition: \[ K = ULU^\top, \qquad \text{keep only the } m \text{ leading eigenvectors} \] \[ \phi(x) = L_m^{-1/2} U_m^\top K(x), \qquad K(x) = [k(x_i,x)]_{1\leq i \leq n} \]
2:50–2:55 · 5 min
Recall linear PCA: find \(w\), \(\|w\|=1\), maximizing \(w^\top \Sigma w\) with \(\Sigma = \frac1n \sum_i x_i x_i^\top\).
Do the same in feature space: replace \(x_i\) with \(\phi(x_i)\), \[ \Sigma_\phi = \frac1n \sum_i \phi(x_i)\phi(x_i)^\top \]
Since the objective only involves inner products of \(\phi(x_i)\) with \(w\), the optimal direction lives in the span of the data: \[ w = \sum_{i=1}^n \alpha_i \phi(x_i) \]
Substitute into the eigenproblem \(\Sigma_\phi w = \lambda w\), then project both sides onto each \(\phi(x_k)\). Every inner product \(\phi(x_i)^\top\phi(x_j)\) becomes \(K_{ij} = k(x_i,x_j)\): \[ K^2 \alpha = n\lambda K \alpha \quad\Longleftarrow\quad K\alpha = n\lambda\alpha \]
Linear PCA subtracts the mean first. In feature space we can’t compute \(\frac1n\sum_i \phi(x_i)\) explicitly, but we can center the Gram matrix instead: \[ \tilde K = K - \mathbf{1}_n K - K \mathbf{1}_n + \mathbf{1}_n K \mathbf{1}_n \] with \(\mathbf{1}_n\) the \(n\times n\) matrix of all \(1/n\) entries.
Once \(\alpha^{(k)}\) solves \(\tilde K \alpha^{(k)} = n\lambda_k \alpha^{(k)}\), the \(k\)-th kernel-PCA coordinate of a (possibly new) point \(x\) is \[ y_k(x) = \sum_{i=1}^n \alpha_i^{(k)}\, k(x_i, x) \]
2:55–3:00 · 5 min