Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

13. Basics of Machine Learning

CNRS & DMA, École Normale Supérieure

Chapter PDF · Complete book

Machine learning seeks useful structure in data and predictors that remain accurate on new observations. We begin with dimensionality reduction and clustering, then develop regression and classification through empirical risk minimization, regularization, and kernel methods. Connections with inverse problems explain the role of model assumptions, while the final analysis of generalization balances approximation error against the statistical complexity of the chosen model class.

Imaging problems often concern the reconstruction or processing of an individual signal or image, whereas machine learning studies patterns across collections of observations. Their goals and performance measures differ, but both use tools such as linear models, regularization, and convex optimization.

13.1 Unsupervised Learning

In unsupervised learning, we observe nn points (xi)i=1n(x_i)_{i=1}^n.

The aim is to identify structure in these observations, for example to visualize them or group them into clusters.

We assume for simplicity that the observations lie in Euclidean space, xiRpx_i \in \mathbb{R}^p, where pp is the number of features. We store the observations as the rows of a matrix XRn×pX\in\mathbb{R}^{n\times p}.

13.1.1 Dimensionality Reduction and PCA

Dimensionality reduction produces a compact representation of the data for visualization or subsequent analysis. By retaining informative features, it can also reduce computational cost and improve prediction.

Principal component analysis (PCA) projects the data orthogonally onto the principal axes of the covariance matrix.

Presentation of the method.

The empirical mean is defined as

m^:=1ni=1nxiRp\hat m \mathrel{:=}\frac{1}{n} \sum_{i=1}^n x_i \in \mathbb{R}^p

and the empirical covariance as

C^:=1ni=1n(xim^)(xim^)Rp×p.(13.1)\hat C \mathrel{:=}\frac{1}{n} \sum_{i=1}^n (x_i-\hat m) (x_i-\hat m)^* \in \mathbb{R}^{p \times p}. \tag{13.1}

With the centered data matrix X~:=X1nm^\tilde X \mathrel{:=}X-\mathbb{1}_n\hat m^*, the covariance is C^=X~X~/n\hat C=\tilde X^* \tilde X/n.

Suppose the points (xi)i(x_i)_i are i.i.d. with a finite second moment, and let x\mathbf{x} denote a random variable with their common distribution. The law of large numbers gives the following almost sure limits as n+n \rightarrow +\infty:

m^m:=E(x)andC^C:=E((xm)(xm)).(13.2)\hat m \rightarrow m \mathrel{:=}\mathbb{E}(\mathbf{x}) \quad \text{and} \quad \hat C \rightarrow C \mathrel{:=}\mathbb{E}((\mathbf{x}-m)(\mathbf{x}-m)^*). \tag{13.2}

Let μ\mu be the distribution on Rp\mathbb{R}^p of x\mathbf{x}. Then these limits can also be written as

m=Rpxdμ(x)andC=Rp(xm)(xm)dμ(x).m = \int_{\mathbb{R}^p} x \mathrm{d}\mu(x) \quad \text{and} \quad C = \int_{\mathbb{R}^p} (x-m)(x-m)^* \mathrm{d}\mu(x).

Figure 13.1. Empirical covariance of the Iris measurements and its eigenvalues.

Figure 13.2. Principal directions of variation.

The PCA basis consists of the right singular vectors of the centered data matrix. Proposition 9.1 gives the reduced singular value decomposition

X~=nUdiag(σ)V\tilde X = \sqrt{n} U \mathop{\mathrm{diag}}(\sigma) V^*

where URn×rU \in \mathbb{R}^{n \times r} and VRp×rV \in \mathbb{R}^{p \times r} have orthonormal columns, and r=rank(X~)min(n,p)r=\mathop{\mathrm{rank}}(\tilde X) \leqslant\min(n,p).

Write V=(vk)k=1rV=(v_k)_{k=1}^r for the orthonormal columns, which are eigenvectors of C^=Vdiag(σ2)V\hat C = V \mathop{\mathrm{diag}}(\sigma^2) V^\top, with vkRpv_k \in \mathbb{R}^p. These vectors describe the principal directions of variation in the point cloud (xi)i(x_i)_i in Rp\mathbb{R}^p.

We order the singular values as σ1σr\sigma_1 \geqslant\ldots \geqslant\sigma_r, so the leading components account for the greatest variance.

Figure 13.1 displays an empirical covariance matrix and its spectrum (σk2)k(\sigma_k^2)_k for the Iris dataset (Iris flower data set) introduced by Fisher. It contains 50 samples from each of three iris species: Iris setosa, Iris virginica, and Iris versicolor. The four features are sepal length, sepal width, petal length, and petal width.

To obtain a PCA embedding xiRpziRdx_i \in \mathbb{R}^p \mapsto z_i \in \mathbb{R}^d of dimension dpd \leqslant p, project onto the first dd right singular vectors, extending the basis if d>rd>r:

zi:=(xim^,vk)k=1dRd.(13.3)z_i \mathrel{:=}( \langle x_i-\hat m,\,v_k\rangle )_{k=1}^d \in \mathbb{R}^d. \tag{13.3}

The corresponding reconstruction is

x~i:=m^+k=1dzi,kvkRp.(13.4)\tilde x_i\mathrel{:=}\hat m+\sum_{k=1}^d z_{i,k}v_k \in \mathbb{R}^p. \tag{13.4}

Thus x~i=ProjT~(xi)\tilde x_i = \mathop{\mathrm{Proj}}_{\tilde T}(x_i), where T~:=m^+Spank=1d(vk)\tilde T\mathrel{:=}\hat m+ \mathop{\mathrm{Span}}_{k=1}^d(v_k) is the affine reconstruction space.

Figure 13.3 shows an example of PCA for 2-D and 3-D visualization.

Figure 13.3. PCA projections of the data into two and three dimensions.

Optimality analysis.

Figure 13.4. Rows of the centered data matrix are observations; columns are features.

We prove that PCA minimizes the 2\ell^2 reconstruction error among linear dimensionality-reduction methods.

An optimal affine reconstruction space can be chosen to contain the empirical mean: for any fixed direction space, translating it to the mean cannot increase squared reconstruction error. After centering, we therefore assume m^=0\hat m=0, hence X=X~X=\tilde X.

We recall that X=nUdiag(σ)VX=\sqrt{n}U\mathop{\mathrm{diag}}(\sigma)V^\top with observations in rows, and C^=XX/n=Vdiag(σi2)V\hat C=X^\top X/n=V\mathop{\mathrm{diag}}(\sigma_i^2)V^\top. We assume 1kp1\leqslant k\leqslant p and extend VV to an orthogonal basis of Rp\mathbb{R}^p when necessary.

Figure 13.5. Linear compression followed by reconstruction.

For the centered data, compare linear compression maps into dimension kk followed by reconstruction:

minR,S  {f(R,S):=i ⁣xiRSxi ⁣Rp2  ;  R,SRp×k}(13.5)\underset{R,S}{\min}\; \left\{ f(R,S) \mathrel{:=}\sum_i |\!| x_i-R S^\top x_i |\!|_{\mathbb{R}^p}^2 \;;\; R,S \in \mathbb{R}^{p \times k} \right\} \tag{13.5}

Although f(,S)f(\cdot,S) and f(R,)f(R,\cdot) are convex separately, ff is not jointly convex. Alternating minimization in RR and SS therefore need not reach a global minimizer.

Nevertheless, a global minimizer has a simple explicit form.

The compressor SS^\top and decompressor R=SR=S give precisely the PCA maps in (13.3) and (13.4).

We first prove that one can restrict attention to orthogonal projection matrices.

The next lemma bounds the objective by a linear program. We then show that PCA attains this bound, proving optimality.

13.1.2 Clustering and kk-means

Clustering assigns a label yi{1,,k}y_i \in \{1,\ldots,k\} to each observation xix_i. Observations with the same label form a cluster.

kk-means

One approach is to seek compact clusters by minimizing a measure of within-cluster dispersion. In Euclidean space, the kk-means objective measures distances from observations to their centroids c=(c)=1kc=(c_\ell)_{\ell=1}^k, with cRpc_\ell \in \mathbb{R}^p. Related formulations are possible in general metric spaces, although the centroid computations may be more difficult. The optimization problem is

min(y,c)  E(y,c):==1ki:yi= ⁣xic ⁣2.\underset{ (y,c) }{\min}\; \mathcal{E}( y, c ) \mathrel{:=}\sum_{\ell=1}^k \sum_{ i : y_i=\ell } |\!| x_i-c_\ell |\!|^2.

Figure 13.7. kk-means clusters according to Voronoi cells.

The kk-means algorithm alternates between updating the labels and updating the centroids, a form of block coordinate minimization.

Initialize the centroids cc, for example by choosing well-separated observations. We discuss a more systematic initialization below.

For fixed centroids cc, minimize yE(y,c)y \mapsto \mathcal{E}(y,c) by assigning each observation to its nearest centroid:

i{1,,n},yiargmin1k   ⁣xic ⁣.(13.7)\forall \,i \in \{1,\ldots,n\}, \quad y_i \leftarrow \underset{1 \leqslant\ell \leqslant k}{\mathop{\mathrm{argmin}}}\; |\!| x_i-c_\ell |\!|. \tag{13.7}

For fixed labels yy, minimize cE(y,c)c \mapsto \mathcal{E}(y,c) by setting each centroid to the mean of its cluster:

{1,,k},ci:yi=xi{i  ;  yi=}(13.8)\forall \,\ell \in \{1,\ldots,k\}, \quad c_\ell \leftarrow \frac{ \sum_{i : y_i=\ell} x_i }{ | \left\{ i \;;\; y_i=\ell \right\} | } \tag{13.8}

If a cluster becomes empty, its centroid does not contribute to the objective for the current labels. One may leave it in place or reseed it at a data point before the next assignment step. The centroid formula applies only to nonempty clusters.

Each step decreases or preserves E\mathcal{E}. With a fixed tie-breaking rule that retains existing assignments at ties, and without indefinite reseeding, a changed assignment strictly decreases the objective. There are finitely many label assignments, so the algorithm terminates after finitely many such changes.

Because the objective is nonconvex, kk-means need not find globally optimal clusters.

A reseeding heuristic moves centroids cc_\ell from redundant or low-contribution clusters to regions with high distortion. This can help the iterations escape a poor local configuration.

Figure 13.8 shows an example of kk-means iterations on the Iris dataset.

Figure 13.8. Left: iterations of the kk-means algorithm. Right: class histograms after the kk-means optimization.

kk-means++

The result of kk-means depends strongly on initialization. Well-separated initial centers tend to cover the data more effectively than tightly grouped centers.

The randomized kk-means++ initialization has an approximation guarantee even before Lloyd iterations are applied. In practice, Lloyd iterations usually improve the resulting centers. First choose c1c_1 uniformly among the sample points. After choosing c1,,cc_1,\ldots,c_\ell, select c+1c_{\ell+1} from the sample according to a probability π()\pi^{(\ell)} on {1,,n}\{1,\ldots,n\} proportional to the squared distance from the nearest selected center

i{1,,n},πi():=di2j=1ndj2wheredi:=min1r ⁣xicr ⁣.\forall \,i \in \{1,\ldots,n\}, \quad \pi^{(\ell)}_i \mathrel{:=}\frac{d_i^2}{\sum_{j=1}^n d_j^2} \quad \text{where} \quad d_i\mathrel{:=}\min_{1\leqslant r\leqslant\ell}|\!| x_i-c_r |\!|.

Points far from the previously seeded centers are more likely to be chosen. If every di=0d_i=0, the current centers already achieve zero distortion and the procedure can stop.

The following theorem, due to David Arthur and Sergei Vassilvitskii, bounds the expected seeding cost by a logarithmic factor times the optimal cost. Computing a global optimum is NP-hard in general.

Lloyd algorithm and continuous densities.

The kk-means iterations are also known as Lloyd’s algorithm and are used in vector quantization for compression. The same alternating procedure applies to a probability measure μ\mu on Rp\mathbb{R}^p with finite second moment.

The energy to minimize becomes

min(V,c)  =1kV ⁣xc ⁣2dμ(x)\underset{ (\mathcal{V},c) }{\min}\; \sum_{\ell=1}^k \int_{\mathcal{V}_\ell} |\!| x-c_\ell |\!|^2 \mathrm{d}\mu(x)

where (V)(\mathcal{V}_\ell)_\ell is a partition of the domain.

Step (13.7) is replaced by the computation of a Voronoi cell

{1,,k},V:={x  ;  , ⁣xc ⁣ ⁣xc ⁣}.\forall \,\ell \in \{1,\ldots,k\}, \quad \mathcal{V}_\ell \mathrel{:=} \left\{ x \;;\; \forall \,\ell' \neq \ell, |\!| x-c_\ell |\!| \leqslant|\!| x-c_{\ell'} |\!| \right\} .

For distinct centroids, the Voronoi cells are polyhedra bounded by perpendicular bisectors. Resolve distance ties consistently to obtain a partition; this matters if μ\mu assigns positive mass to a boundary. In low dimensions, computational geometry provides efficient algorithms for constructing the cells.

Step (13.8) is then replaced by

{1,,k},cVxdμ(x)Vdμ(x).\forall \,\ell \in \{1,\ldots,k\}, \quad c_\ell \leftarrow \frac{ \int_{\mathcal{V}_\ell} x \mathrm{d}\mu(x) }{ \int_{\mathcal{V}_\ell} \mathrm{d}\mu(x) }.

The centroid update applies to cells of positive μ\mu-mass; zero-mass cells require a separate convention, as in the discrete algorithm. For a uniform planar density, hexagonal Voronoi patterns are characteristic of high-resolution quantization away from the boundary. They need not be exact finite-kk minimizers on a bounded domain.

Figure 13.9 displays two examples of Lloyd iterations on 2-D densities on a square domain.

Figure 13.9. Continuous kk-means (Lloyd) iterations 0,2,3,5,300,2,3,5,30. The top row uses a uniform density; the bottom row uses the nonuniform density shown in grayscale.

13.2 Empirical Risk Minimization

We first describe empirical risk minimization, a framework shared by regression and classification. For classification, predictions may represent class probabilities rather than labels.

To make fitting yif(xi)y_i \approx f(x_i) computationally tractable and obtain useful predictions, we restrict the admissible functions to a class of controlled complexity. The class may become richer as the sample size nn grows, but its complexity must remain compatible with the available data.

13.2.1 Empirical Risk

Let Fn\mathcal{F}_n be a class of functions that may depend on the sample size. A common learning procedure is empirical risk minimization (ERM)

f^argminfFn  1ni=1nL(f(xi),yi).(13.9)\hat f \in \underset{f \in \mathcal{F}_n}{\mathop{\mathrm{argmin}}}\; \frac{1}{n} \sum_{i=1}^n L(f(x_i),y_i). \tag{13.9}

The loss function L:Y2R+L: \mathcal{Y}^2 \rightarrow \mathbb{R}^+ measures prediction error for the chosen task. Classification and regression typically require different loss functions.

We sometimes write f^n\hat f_n to emphasize the estimator’s dependence on the sample size nn.

13.2.2 Prediction and Consistency

For the analysis, assume the training pairs (xi,yi)(x_i,y_i) are i.i.d. with distribution π\pi on X×Y\mathcal{X}\times \mathcal{Y}. The corresponding population optimization problem is

fˉargminfF  X×YL(f(x),y)dπ(x,y)=E(x,y)π(L(f(x),y)).(13.10)\bar f \in \underset{f \in \mathcal{F}_\infty}{\mathop{\mathrm{argmin}}}\; \int_{\mathcal{X}\times \mathcal{Y}} L(f(x),y) \mathrm{d}\pi(x,y) = \mathbb{E}_{(\mathbf{x},\mathbf{y})\sim\pi}\bigl(L(f(\mathbf{x}),\mathbf{y})\bigr). \tag{13.10}

The desired consistency property is f^nfˉ\hat f_n \rightarrow \bar f as n+n \rightarrow +\infty. One way to express this is through expected prediction error over the training samples (xi,yi)i(x_i,y_i)_i:

En:=E(L~(f^n(x),fˉ(x)))0.E_n \mathrel{:=}\mathbb{E}( \tilde L(\hat f_n(\mathbf{x}),\bar f(\mathbf{x})) ) \longrightarrow 0.

Here the expectation includes both the test input x\mathbf{x}, drawn from the marginal πX\pi_\mathcal{X}, and the nn i.i.d. training pairs (xi,yi)π(x_i,y_i)\sim\pi that determine f^n\hat f_n.

The comparison loss L~\tilde L measures discrepancies between predictions in Y\mathcal{Y}; for example, we may take L~=L\tilde L=L. One can also study convergence in probability, i.e.

ε>0,Eε,n:=P(L~(f^n(x),fˉ(x))>ε)0.\forall \,\varepsilon>0, \quad E_{\varepsilon,n} \mathrel{:=}\mathbb{P}( \tilde L(\hat f_n(\mathbf{x}),\bar f(\mathbf{x})) > \varepsilon) \rightarrow 0.

These properties define consistency in expectation and in probability, respectively.

A convergence rate gives an explicit upper bound on the decay of EnE_n or Eε,nE_{\varepsilon,n}.

For L~(y,y)=yyr\tilde L(y,y')=|y-y'|^r, convergence in expectation implies convergence in probability by Markov’s inequality:

Eε,n=P(f^n(x)fˉ(x)r>ε)1εE(f^n(x)fˉ(x)r)=Enε.E_{\varepsilon,n} = \mathbb{P}( |\hat f_n(\mathbf{x})-\bar f(\mathbf{x})|^r > \varepsilon) \leqslant\frac{1}{\varepsilon} \mathbb{E}( |\hat f_n(\mathbf{x})-\bar f(\mathbf{x})|^r ) = \frac{E_n}{\varepsilon}.

13.2.3 Parametric Approaches and Regularization

Instead of specifying Fn\mathcal{F}_n through a hard constraint, we can favor simple or regular functions through a penalty.

A typical way to achieve this is by using a parametric model yf(x,β)y \approx f(x,\beta) where βB\beta\in \mathcal{B} parametrizes the function f(,β):XYf(\cdot,\beta) : \mathcal{X}\rightarrow \mathcal{Y}. The empirical risk minimization procedure (13.9) now becomes

β^argminβB  1ni=1nL(f(xi,β),yi)+λnJ(β).(13.11)\hat \beta\in \underset{\beta\in \mathcal{B}}{\mathop{\mathrm{argmin}}}\; \frac{1}{n} \sum_{i=1}^n L(f(x_i,\beta),y_i) + \lambda_n J(\beta). \tag{13.11}

where JJ is a regularizer. For example, J= ⁣ ⁣22J=|\!| \cdot |\!|_2^2 controls parameter magnitude, while J= ⁣ ⁣1J=|\!| \cdot |\!|_1 promotes sparse coefficients and, in a linear feature model, feature selection. Here λn>0\lambda_n>0 is a regularization parameter, and its asymptotic scaling must balance approximation and estimation; consistency often requires λn0\lambda_n\to0 at a controlled rate.

The population counterpart of (13.10) defines the parameter βˉ\bar \beta. A limiting estimator as n+n \rightarrow +\infty then takes the form fˉ=f(,βˉ)\bar f = f(\cdot,\bar \beta), with βˉ\bar \beta satisfying

βˉargminβ  X×YL(f(x,β),y)dπ(x,y)=E(x,y)π(L(f(x,β),y)).(13.12)\bar \beta\in \underset{\beta}{\mathop{\mathrm{argmin}}}\; \int_{\mathcal{X}\times \mathcal{Y}} L(f(x,\beta),y) \mathrm{d}\pi(x,y) = \mathbb{E}_{(\mathbf{x},\mathbf{y})\sim\pi}\bigl(L(f(\mathbf{x},\beta),\mathbf{y})\bigr). \tag{13.12}

Prediction vs. estimation risks.

We may also ask how accurately β^\hat\beta estimates βˉ\bar\beta, as measured by the parameter error  ⁣β^βˉ ⁣|\!| \hat\beta-\bar\beta |\!| for a chosen norm  ⁣ ⁣|\!| \cdot |\!|. Parameter estimation is generally more demanding than prediction: different parameters can produce similar predictions, especially when the model is poorly identified.

13.2.4 Validation, Test Sets, and Cross-validation

The errors EnE_n and Eε,nE_{\varepsilon,n} cannot be evaluated directly because the population optimum fˉ\bar f is unknown.

To tune a parameter such as the regularization strength λ\lambda, we estimate the prediction risk E(L(f^(x),y))\mathbb{E}(L(\hat f(\mathbf{x}),\mathbf{y})) on data held out from training.

Use a second sample (xˉj,yˉj)j=1nˉ(\bar x_j,\bar y_j)_{j=1}^{\bar n}, called a validation set. In the statistical model, these observations are i.i.d. with distribution π\pi and independent of the training sample. The validation risk is

Rnˉ=1nˉj=1nˉL(f^(xˉj),yˉj)(13.13)R_{\bar n} = \frac{1}{\bar n} \sum_{j=1}^{\bar n} L(\hat f(\bar x_j),\bar y_j) \tag{13.13}

which converges to E(L(f^(x),y))\mathbb{E}(L(\hat f(\mathbf{x}),\mathbf{y})) for large nˉ\bar n.

Minimizing RnˉR_{\bar n} over hyperparameters (such as λn\lambda_n) is holdout validation. Cross-validation repeats training and validation across folds. A separate test set, untouched by hyperparameter selection, estimates the performance of the final selected procedure.

13.3 Supervised Learning: Regression

Figure 13.10. Probabilistic modeling.

In supervised learning, the training data consist of pairs (xi,yi)X×Y(x_i,y_i)\in\mathcal{X}\times\mathcal{Y}, with X=Rp\mathcal{X}=\mathbb{R}^p here for simplicity. We seek a function f:XYf:\mathcal{X}\rightarrow\mathcal{Y} that captures the relationship yif(xi)y_i\approx f(x_i) and predicts an output f(x)f(x) for a new input xx.

When Y\mathcal{Y} is finite and discrete, the task is supervised classification, studied in Section 13.4. Binary classification uses Y={0,1}\mathcal{Y}=\{0,1\}; for example, in a medical application, yi=0y_i=0 may indicate a healthy subject and yi=1y_i=1 a subject with the condition of interest.

When Y\mathcal{Y} is continuous, typically Y=R\mathcal{Y}=\mathbb{R}, the task is regression.

13.3.1 Linear Regression

For regression, we specialize empirical risk minimization to Y=R\mathcal{Y}=\mathbb{R} with the quadratic loss L(y,y)=12yy2L(y,y')=\frac{1}{2}|y-y'|^2.

Nonlinear regression can be formulated using a dictionary of features, such as polynomials. This lifts the data into a higher-dimensional space and leads to the kernel methods of Section 13.5.

Least squares and conditional expectation.

If ff ranges over measurable functions and E(y2)<\mathbb{E}(\mathbf{y}^2)<\infty, a population minimizer fˉ\bar f in (13.10) is the conditional mean of the response given the input. It is defined up to equality almost everywhere under the input distribution.

Suppose for simplicity that π\pi has density dπdxdy\frac{\mathrm{d}\pi}{\mathrm{d}x \mathrm{d}y} with respect to a product measure dxdy\mathrm{d}x \mathrm{d}y, such as Lebesgue measure. Then

xX,fˉ(x)=E(yx=x)=Yydπdxdy(x,y)dyYdπdxdy(x,y)dy\forall \,x \in \mathcal{X}, \quad \bar f(x) = \mathbb{E}( \mathbf{y}| \mathbf{x}=x) = \frac{ \int_{\mathcal{Y}} y \frac{\mathrm{d}\pi}{\mathrm{d}x \mathrm{d}y}(x,y) \mathrm{d}y }{ \int_{\mathcal{Y}} \frac{\mathrm{d}\pi}{\mathrm{d}x \mathrm{d}y}(x,y) \mathrm{d}y }

where (x,y)(\mathbf{x},\mathbf{y}) has law π\pi and the formula applies where the denominator is positive.

Figure 13.11. Conditional expectation.

If X\mathcal{X} and Y\mathcal{Y} are discrete, let πx,y\pi_{x,y} denote the probability of (x=x,y=y)(\mathbf{x}=x,\mathbf{y}=y). Then

xX,fˉ(x)=yyπx,yyπx,y\forall \,x \in \mathcal{X}, \quad \bar f(x) = \frac{ \sum_{y} y \pi_{x,y} }{ \sum_{y} \pi_{x,y} }

with no prescribed value when the marginal of π\pi on X\mathcal{X} vanishes at xx.

Replacing π\pi by the empirical distribution averages responses at each observed input but leaves predictions unspecified elsewhere. Generalization therefore requires assumptions on regularity or model complexity.

Penalized linear models.

Figure 13.12. Linear regression.

A linear model constrains ff to have the form f(x,β)=x,βf(x,\beta)=\langle x,\,\beta\rangle with parameters βB=Rp\beta\in \mathcal{B}=\mathbb{R}^p. Affine predictors are included through the identity x,β+β0=(x,1),(β,β0)\langle x,\,\beta\rangle+\beta_0=\langle (x,1),\,(\beta,\beta_0)\rangle, by appending a constant coordinate to xx to form (x,1)(x,1). We therefore use the linear notation below.

Under the square loss, the regularized ERM (13.11) is conveniently rewritten as

β^argminβB  12C^β,βu^,β+λnJ(β)(13.14)\hat \beta\in \underset{\beta\in \mathcal{B}}{\mathop{\mathrm{argmin}}}\; \frac{1}{2} \langle \hat C \beta,\,\beta\rangle - \langle \hat u,\,\beta\rangle + \lambda_n J(\beta) \tag{13.14}

where we introduced the empirical second-moment matrix (equal to the covariance (13.1) for centered data) and cross-moment vector

C^:=1nXX=1ni=1nxixiandu^:=1ni=1nyixi=1nXyRp.\hat C \mathrel{:=}\frac{1}{n} X^* X = \frac{1}{n} \sum_{i=1}^n x_i x_i^* \quad \text{and} \quad \hat u \mathrel{:=}\frac{1}{n} \sum_{i=1}^n y_i x_i = \frac{1}{n} X^* y \in \mathbb{R}^p.

As n+n\to+\infty, suitable moment assumptions on π\pi give the following almost sure limits by the law of large numbers:

C^C:=E(xx)andu^u:=E(yx).(13.15)\hat C \rightarrow C \mathrel{:=}\mathbb{E}(\mathbf{x}\mathbf{x}^*) \quad \text{and} \quad \hat u \rightarrow u \mathrel{:=}\mathbb{E}(\mathbf{y}\mathbf{x}). \tag{13.15}

For appropriately chosen λn0\lambda_n \rightarrow 0, the estimator can converge as n+n \rightarrow +\infty to the population parameter

βˉargminβ  {J(β)  ;  Cβ=u}.\bar \beta\in \underset{\beta}{\mathop{\mathrm{argmin}}}\; \left\{ J(\beta) \;;\; C\beta=u \right\} .

Problem (13.14) is equivalent to the regularized resolution of inverse problems (9.9), with X/nX/\sqrt n in place of Φ\Phi and y/ny/\sqrt n as the observation vector.

Random design introduces sampling error into the operator as well: C^\hat C estimates CC. The typical scale is 1/n1/\sqrt{n}, in the sense that

E( ⁣C^C ⁣)=O(n1/2)andE( ⁣u^u ⁣)=O(n1/2),\mathbb{E}(|\!| \hat C-C |\!|) =O(n^{-1/2}) \quad \text{and} \quad \mathbb{E}(|\!| \hat u-u |\!|) =O(n^{-1/2}),

assuming E(y4)<+\mathbb{E}(\mathbf{y}^4)<+\infty and E( ⁣x ⁣4)<+\mathbb{E}(|\!| \mathbf{x} |\!|^4)<+\infty, which give finite second moments for xx\mathbf{x}\mathbf{x}^* and xy\mathbf{x}\mathbf{y}. Using a linear predictor does not require a correctly specified model y=x,β+w\mathbf{y}=\langle \mathbf{x},\,\beta\rangle + w with noise ww independent of x\mathbf{x}. The aim is to estimate the best linear predictor βˉ\bar\beta.

Extensions of Theorems 9.4, 11.9, and 11.11 can account for covariance-estimation error and yield prediction bounds of the form

E(β^,xβˉ,x2)=O(nκ)\mathbb{E}( |\langle \hat \beta,\,\mathbf{x}\rangle-\langle \bar \beta,\,\mathbf{x}\rangle|^2 ) = O( n^{-\kappa} )

and estimation rates of the form

E( ⁣β^βˉ ⁣2)=O(nκ),\mathbb{E}( |\!| \hat \beta-\bar \beta |\!|^2 ) = O( n^{-\kappa'} ),

under suitable source conditions involving CC and uu.

Since the noise level is roughly n12n^{-\frac{1}{2}}, the ideal cases are when κ=κ=1\kappa=\kappa'=1, which is the so-called linear rate regime.

Support-recovery guarantees can also be derived by extending Theorem 11.15. We now focus on quadratic regularization, a standard regression method. Sparse penalties such as 1\ell^1 are useful when feature selection or a sparse model is appropriate; their statistical benefit depends on the data and assumptions.

In imaging inverse problems, sparse regularization expresses prior structure of the object being reconstructed.

Ridge regression (quadratic penalization).

For J= ⁣ ⁣2/2J=|\!| \cdot |\!|^2/2, the estimator (13.14) is obtained in closed form as

β^=(XX+nλnIdp)1Xy=(C^+λnIdp)1u^.(13.16)\hat\beta= ( X^* X + n\lambda_n \mathrm{Id}_p )^{-1} X^* y = (\hat C+\lambda_n\mathrm{Id}_p)^{-1}\hat u. \tag{13.16}

This is often called ridge regression in the literature.

The Woodbury identity gives the equivalent expression

β^=X(XX+nλnIdn)1y.(13.17)\hat\beta= X^* ( XX^* + n\lambda_n \mathrm{Id}_n )^{-1} y . \tag{13.17}

When npn\gg p, formula (13.16) requires solving the smaller, p×pp\times p system. When pnp\gg n, formula (13.17) uses an n×nn\times n system and is preferable; it also extends to infinite-dimensional feature spaces.

Convergence to the minimum-norm population solution βˉ=C+u\bar\beta=C^+u requires control of both the regularization bias and sampling error. The condition λn0\lambda_n\to0 alone is insufficient when small eigenvalues amplify noise. Here is one elementary bound that also applies in a Hilbert feature space.

In finite dimensions, a source representation exists for every βˉIm(C)\bar\beta\in\mathop{\mathrm{Im}}(C), but its radius ρ\rho depends on the spectrum and on the target. In infinite dimensions, it is an additional regularity assumption. The bound displays no explicit feature dimension, although κ\kappa, BB, and ρ\rho may depend on it. Standard ridge regularization has bias saturation beyond source exponent γ=1\gamma=1; stronger source assumptions alone do not justify extending this estimate to γ=2\gamma=2.

13.4 Supervised Learning: Classification

For classification, the labels are discrete: yiY={1,,k}y_i \in \mathcal{Y}= \{1,\ldots,k\}.

We study two standard methods: nearest neighbors and logistic classification.

Both methods provide useful baselines for assessing more elaborate models.

Nearest-neighbor methods also apply to regression.

13.4.1 Nearest-Neighbor Classification

The RR-nearest-neighbor method (RR-NN) classifies an input using the labels of its RR nearest training observations. Increasing RR reduces sensitivity to individual noisy labels, but excessive smoothing can obscure class boundaries. For consistency, a standard asymptotic choice has R=RnR=R_n\to\infty and Rn/n0R_n/n\to0.

Nearest-neighbor classification is a useful baseline, especially when the feature dimension pp is small.

The prediction f^(x)Y\hat f(x)\in\mathcal{Y} is the most frequent label among those RR observations, with a fixed rule for breaking ties. The method is nonparametric: its representation depends on the training sample rather than on a fixed-dimensional parameter vector.

Figure 13.13. Nearest neighbors.

First compute the Euclidean distance from the query xx to each training observation xix_i.

Sorting the distances generates an indexing σ\sigma (a permutation of {1,,n}\{1,\ldots,n\}) such that

 ⁣xxσ(1) ⁣ ⁣xxσ(2) ⁣ ⁣xxσ(n) ⁣.|\!| x-x_{\sigma(1)} |\!| \leqslant|\!| x-x_{\sigma(2)} |\!| \leqslant\ldots \leqslant|\!| x-x_{\sigma(n)} |\!|.

For a given RR, one can compute the “local” histogram of classes around xx

h(x):=1R#{i{1,,R}:yσ(i)=}.h_\ell(x)\mathrel{:=}\frac1R\#\{i\in\{1,\ldots,R\}:y_{\sigma(i)}=\ell\}.

The predicted class at xx is an index attaining the largest histogram value:

f^(x)argmax  h(x).\hat f(x) \in \underset{\ell}{\mathop{\mathrm{argmax}}}\; h_\ell(x).

Choose RR by validation or cross-validation. For classification, the validation risk (13.13) typically uses the 0–1 loss, giving the fraction of misclassified observations

Rnˉ:=1nˉj=1nˉδ(yˉjf^(xˉj))R_{\bar n}\mathrel{:=}\frac1{\bar n}\sum_{j=1}^{\bar n}\delta(\bar y_j-\hat f(\bar x_j))

where δ(0)=0\delta(0)=0 and δ(s)=1\delta(s)=1 if s0s \neq 0.

The method also applies to features in a general metric space in place of Rp\mathbb{R}^p.

Fast nearest-neighbor search can avoid explicitly sorting every distance.

Figure 13.14. Classification boundaries produced by RR-nearest neighbors.

Figure 13.14 shows the predicted class regions {x  ;  f^(x)=}\left\{ x \;;\; \hat f(x)=\ell \right\}, for =1,,k\ell=1,\ldots,k, in a two-dimensional projection of the Iris dataset.

Increasing RR leads to smoother class boundaries.

13.4.2 Binary Logistic Classification

Logistic classification is a widely used baseline for binary and multiclass prediction. It outputs a probability for each class, providing a richer prediction than a class label alone. The accuracy of these probabilities must still be assessed on held-out data.

The standard name for this model is logistic regression, even when the prediction task is classification.

Support vector machines provide another common approach. Their hinge loss is nonsmooth, and their scores are not probabilities without an additional calibration step. The choice between these methods depends on the task and evaluation criterion.

For the binary formulas below, use labels yiY={1,1}y_i \in \mathcal{Y}= \{-1,1\}. In logistic classification, the prediction f(,β)[0,1]f(\cdot,\beta) \in [0,1] is a probability for the positive class rather than a class label. We retain the notation ff for this probability predictor.

Approximate risk minimization.

A linear score x,β\langle x,\,\beta\rangle defines the classifier sign(x,β)\mathop{\mathrm{sign}}(\langle x,\,\beta\rangle), with either class assigned when the score is zero. The empirical 0–1 objective counts classification errors, leading to the minimization problem

minβ  i=1n0(yixi,β)(13.20)\underset{\beta}{\min}\; \sum_{i=1}^n \ell_0(-y_i \langle x_i,\,\beta\rangle) \tag{13.20}

where 0=1[0,+)\ell_0=1_{[0,+\infty)} counts zero margins as errors. Away from ties, misclassification corresponds to xi,β\langle x_i,\,\beta\rangle and yiy_i having different signs, so that in this case 0(yixi,β)=1\ell_0(-y_i \langle x_i,\,\beta\rangle)=1 (and 0 otherwise for correct classification).

The loss 0\ell_0 is nonconvex, and solving (13.20) globally is NP-hard in general. Convex upper bounds on 0\ell_0 provide tractable surrogate objectives.

Two common surrogates are

(u)=(1+u)+and(u)=log(1+exp(u))/log(2)\ell(u)=(1+u)_+ \quad \text{and} \quad \ell(u)=\log(1+\exp(u))/\log(2)

These are, respectively, the nonsmooth hinge loss used in support vector machines and the smooth logistic loss. The 1/log(2)1/\log(2) is just a constant which makes 0\ell_0 \leqslant\ell.

AdaBoost uses the exponential loss (u)=eu\ell(u)=e^u.

Least squares uses (u)=(1+u)2\ell(u)=(1+u)^2. Its growth for large negative margins makes it a poor pointwise approximation of 0\ell_0, although it can still give useful classifiers.

Unregularized hinge-loss minimization is equivalent to a linear program with nonnegative slack variables:

minu0,β  {iui  ;  yixi,β1ui for all i}.\underset{u \geqslant 0, \beta}{\min}\; \left\{ \sum_i u_i \;;\; y_i\langle x_i,\,\beta\rangle\geqslant 1-u_i\text{ for all }i \right\} .

Logistic loss probabilistic interpretation.

Logistic regression applies a sigmoid to the linear score from Section 13.3.1. The resulting probability predictor is nonlinear. The predicted probability of class +1 is

f(x,β):=θ(x,β)whereθ(s):=es1+es=(1+es)1,(13.21)f(x,\beta) \mathrel{:=}\theta(\langle x,\,\beta\rangle) \quad \text{where} \quad \theta(s) \mathrel{:=}\frac{e^{s}}{1+e^s} = (1+e^{-s})^{-1}, \tag{13.21}

which is often called the “logit” model.

Despite its simplicity, a linear classifier can be effective when the feature dimension pp is large.

With s=x,βs=\langle x,\,\beta\rangle, the predicted probability of class -1 is 1f(x,β)=θ(s)1-f(x,\beta)=\theta(-s). The identity θ(s)=1θ(s)\theta(-s)=1-\theta(s) makes the two probabilities sum to one. It does not require balanced class frequencies; an intercept can account for unequal prior frequencies.

For a nonzero parameter, β/ ⁣β ⁣\beta/|\!| \beta |\!| determines the normal direction of the separating hyperplane, while 1/ ⁣β ⁣1/|\!| \beta |\!| controls the width of the probability transition. As  ⁣β ⁣+|\!| \beta |\!| \rightarrow +\infty along a fixed direction, the transition approaches a sharp decision boundary.

Figure 13.15. Logistic classification in one and two dimensions, showing how  ⁣β ⁣|\!| \beta |\!| controls the width of the probability transition.

The predictor f(x,β)f(x,\beta) is also a single-layer perceptron with a logistic (sigmoid) activation; see Chapter 17.

For conditionally independent labels yi{1,+1}y_i\in\{-1,+1\}, write yˉi=(yi+1)/2{0,1}\bar y_i=(y_i+1)/2\in\{0,1\}, si=xi,βs_i=\langle x_i,\,\beta\rangle, and pi=θ(si)p_i=\theta(s_i). The likelihood is

P(y=yix=xi)=piyˉi(1pi)1yˉi.\mathbb{P}(\mathbf{y}=y_i\mid\mathbf{x}=x_i)=p_i^{\bar y_i}(1-p_i)^{1-\bar y_i}.

Thus the negative log-likelihood is

i{yˉilogpi(1yˉi)log(1pi)}=ilog(1+exp(yisi)).\sum_i\{-\bar y_i\log p_i-(1-\bar y_i)\log(1-p_i)\} =\sum_i\log(1+\exp(-y_is_i)).

After division by the sample size, this gives the empirical-risk objective (13.11) with logistic loss:

β^argminβRp  E(β)=1ni=1nL(xi,β,yi)(13.22)\hat\beta\in \underset{\beta\in \mathbb{R}^p}{\mathop{\mathrm{argmin}}}\; E(\beta) = \frac{1}{n} \sum_{i=1}^n L(\langle x_i,\,\beta\rangle,y_i) \tag{13.22}

where the logistic loss reads

L(s,y):=log(1+exp(sy)).(13.23)L( s,y ) \mathrel{:=}\log( 1+\exp(-sy) ). \tag{13.23}

Problem (13.22) is a smooth convex minimization. If XX has full column rank, EE is strictly convex, so it has at most one minimizer. A finite minimizer need not exist for separable data. A positive quadratic penalty guarantees existence and uniqueness.

Figure 13.16. Classification losses as functions of the negative margin s=yx,βs=-y\langle x,\,\beta\rangle, with zero margin counted as an error. The unscaled logistic loss need not upper-bound the 0–1 loss; division by log2\log 2 gives the upper-bound normalization used above.

Figure 13.16 compares the 0–1, logistic, and hinge losses.

Gradient descent method.

Write the objective as

E(β)=L(Xβ,y)whereL(s,y)=1niL(si,yi),E(\beta) = \mathcal{L}(X \beta,y) \quad \text{where} \quad \mathcal{L}(s,y)= \frac{1}{n} \sum_i L(s_i,y_i),

Its gradient is

E(β)=XL(Xβ,y)whereL(s,y)=ynθ(ys),\nabla E(\beta) = X^* \nabla \mathcal{L}(X \beta,y) \quad \text{where} \quad \nabla\mathcal{L}(s,y)=-\frac{y}{n}\odot\theta(-y\odot s),

where \odot is the pointwise multiplication operator, i.e. .* in Matlab.

Once β(=0)Rp\beta^{(\ell=0)} \in \mathbb{R}^{p} is initialized (for instance at 0p0_{p}), one step of gradient descent (14.13) reads

β(+1)=β()τE(β()).\beta^{(\ell+1)} = \beta^{(\ell)} - \tau_\ell \nabla E(\beta^{(\ell)}).

Figure 13.17. Effect of class separation on predicted classification probabilities.

Figure 13.17 illustrates the method on samples from a Gaussian mixture, whose overlap is controlled by an offset ω\omega.

Overlaying the data on the probability map highlights the separating hyperplane {x  ;  β,x=0}\left\{ x \;;\; \langle \beta,\,x\rangle=0 \right\}.

13.4.3 Multiclass Logistic Classification

For multiclass logistic classification, introduce one weight vector for each of the kk classes. Collect the vectors β=(β)=1k\beta= ( \beta_\ell )_{\ell=1}^k as columns of βRp×k\beta\in \mathbb{R}^{p \times k}.

For an input xRpx \in \mathbb{R}^p, convert the class scores into probabilities using the softmax model:

f(x,β)=(ex,βmex,βm)(13.24)f(x,\beta) = \left( \frac{ e^{\langle x,\,\beta_\ell\rangle} }{ \sum_m e^{\langle x,\,\beta_m\rangle} } \right)_\ell \tag{13.24}

The vector f(x,β)[0,1]kf(x,\beta)\in[0,1]^k gives the probabilities that xx belongs to each class, and satisfies f(x,β)=1\sum_\ell f(x,\beta)_\ell=1.

Estimate β\beta by maximizing the log-likelihood over the training sample:

maxβRp×k  1ni=1nlog(f(xi,β)yi)\underset{\beta\in \mathbb{R}^{p \times k}}{\max}\; \frac{1}{n} \sum_{i=1}^n \log( f(x_i,\beta)_{y_i} )

where yiY={1,,k}y_i \in \mathcal{Y}= \{1,\ldots,k\} is the label of observation xix_i.

This is conveniently rewritten as

minβRp×k  E(β):=1n(iLSE(Xβ)iXβ,D)\underset{\beta\in \mathbb{R}^{p \times k}}{\min}\; \mathcal{E}(\beta)\mathrel{:=}\frac1n\left(\sum_i\text{LSE}(X\beta)_i-\langle X\beta,\,D\rangle\right)

where D{0,1}n×kD \in \{0,1\}^{n \times k} is the one-hot class matrix

Di,={1ifyi=,0otherwise.D_{i,\ell} = \left\{ \begin{array}{l} 1 \quad \text{if} \quad y_i=\ell, \\ 0 \text{otherwise}. \end{array} \right.

and LSE is the log-sum-exp operator

LSE(S)i=log(exp(Si,)),LSE(S)Rn.\text{LSE}(S)_i=\log\left(\sum_\ell\exp(S_{i,\ell})\right),\qquad\text{LSE}(S)\in\mathbb{R}^n.

For k=2k=2, identify the first class with label +1 and the second with label -1. The model then agrees with binary logistic classification in Section 13.4.2, with parameter β1β2\beta_1-\beta_2. A single weight vector therefore suffices in that case.

Direct evaluation of log-sum-exp can overflow when Si,S_{i,\ell} is large. A stable evaluation subtracts the largest entry in each row before exponentiation, using the identity

LSE(S+a)=LSE(S)+a\text{LSE}(S+a)=\text{LSE}(S)+a

for a rowwise constant aa. This shift is especially useful for well-separated classes, whose parameter vectors β\beta_\ell may grow large.

The gradient of the sum of the rowwise log-sum-exp values is the softmax operator

SiLSE(S)i=SM(S):=(eSi,meSi,m)\nabla_S\sum_i\text{LSE}(S)_i = \text{SM}(S) \mathrel{:=} \left( \frac{ e^{S_{i,\ell}} }{ \sum_m e^{S_{i,m}} } \right)

As with log-sum-exp, subtract the largest entry in each row before evaluating the exponentials.

Figure 13.18. Digit images and their two- and three-dimensional PCA projections.

Once the matrix DD is computed, the gradient of E\mathcal{E} is computed as

E(β)=1nX(SM(Xβ)D).\nabla \mathcal{E}(\beta) = \frac{1}{n} X^* ( \text{SM}(X \beta) - D ).

The objective E\mathcal{E} can then be minimized by gradient descent.

To illustrate the method, we use a dataset of nn images of size p=8×8p = 8 \times 8, representing digits from 0 to 9 (so there are k=10k=10 classes).

Figure 13.18 displays a few representative examples as well as 2-D and 3-D PCA projections.

Figure 13.19 visualizes the fitted class probabilities f(x,β^)f(x,\hat\beta) by assigning colors on a regular image grid.

Figure 13.19. Digit classification. Left: the first nine class probabilities on an affine two-dimensional PCA slice through the training mean. Right: the mixture of all ten class colors, with projected observations overlaid.

13.5 Kernel Methods

Linear models may fail to capture the geometry needed for a regression or classification task. Moreover, inputs such as strings and graphs need not belong to a vector space.

Kernel methods introduce a feature map into a richer space and apply linear prediction there. This produces nonlinear regression and classification rules while retaining linear-system solvers and convex optimization. The kernel trick expresses the computations through similarities between the nn observations, without constructing the feature vectors explicitly. Such methods are nonparametric when the number of fitted coefficients grows with nn, allowing the model to become more expressive as data accumulate.

Algorithms that use the observations xix_i only through inner products can often be kernelized. Examples include linear regression, nearest-neighbor methods, SVMs, logistic classification, and PCA. We introduce the construction through ridge regression and then extend it to other losses and distance-based methods.

13.5.1 Feature Map and Kernels

Let φ:XH\varphi: \mathcal{X}\rightarrow \mathcal{H} be a feature map into a real Hilbert space H\mathcal{H}, which may be infinite dimensional.

The input space X\mathcal{X} need not be a vector space. When X=Rp\mathcal{X}=\mathbb{R}^p, the choice φ(x)=x\varphi(x)=x recovers ordinary linear methods.

For regression, we consider predictions which are linear functions over this lifted space, i.e. of the form xφ(x),βHx \mapsto \langle \varphi(x),\,\beta\rangle_\mathcal{H} for some weight vector βH\beta\in \mathcal{H}. For binary classification, one uses xsign(φ(x),βH)x \mapsto \mathop{\mathrm{sign}}(\langle \varphi(x),\,\beta\rangle_\mathcal{H}).

For scalar inputs (p=1p=1), the feature map φ(x)=(1,x,x2,,xk)Rk+1\varphi(x) = (1,x,x^2,\ldots,x^k)\in\mathbb{R}^{k+1} gives polynomial regression. Multivariate monomials extend this construction to higher-dimensional inputs.

Let Φ=(φ(xi))i=1n\Phi = ( \varphi(x_i)^* )_{i=1}^n be the feature matrix, whose rows are φ(xi)\varphi(x_i). For H=Rpˉ\mathcal{H}=\mathbb{R}^{\bar p}, it is an ordinary matrix ΦRn×pˉ\Phi \in \mathbb{R}^{n \times \bar p}. In an infinite-dimensional feature space, the same notation represents a linear operator.

For λ>0\lambda>0, consider the regularized empirical-risk problem

minβH  i=1n(yi,φ(xi),β)+λ2 ⁣β ⁣H2=L(Φβ,y)+λ2 ⁣β ⁣H2(13.25)\underset{\beta\in \mathcal{H}}{\min}\; \sum_{i=1}^n \ell(y_i, \langle \varphi(x_i),\,\beta\rangle) + \frac{\lambda}{2} |\!| \beta |\!|_\mathcal{H}^2 = \mathcal{L}(\Phi \beta,y) + \frac{\lambda}{2} |\!| \beta |\!|_\mathcal{H}^2 \tag{13.25}

Start with regression under the squared loss (y,z)=12(yz)2\ell(y,z)=\frac{1}{2}(y-z)^2:

β=argminβH   ⁣Φβy ⁣Rn2+λ ⁣β ⁣H2.\beta^\star = \underset{\beta\in \mathcal{H}}{\mathop{\mathrm{argmin}}}\; |\!| \Phi\beta-y |\!|_{\mathbb{R}^n}^2+\lambda|\!| \beta |\!|_\mathcal{H}^2.

which is the ridge regression problem studied in Section 13.3.1.

Setting the gradient to zero gives

β=(ΦΦ+λIdH)1Φy.\beta^\star = ( \Phi^*\Phi + \lambda\mathrm{Id}_{\mathcal{H}} )^{-1} \Phi^* y.

Direct computation may be impractical or impossible when H\mathcal{H} is infinite dimensional. The following Woodbury identity converts the problem into a finite system.

This is the feature-space counterpart of (13.17), with Φ\Phi replacing XX and λ\lambda replacing nλnn\lambda_n.

The identity gives the alternative representation

β=Φcwherec:=(K+λIdRn)1y\beta^\star = \Phi^* c^\star \quad \text{where} \quad c^\star \mathrel{:=}( K + \lambda\mathrm{Id}_{\mathbb{R}^n} )^{-1} y

where the empirical kernel matrix is

K=ΦΦ=(κ(xi,xj))i,j=1nRn×nwhereκ(x,x):=φ(x),φ(x).K=\Phi\Phi^* = ( \kappa(x_i,x_j) )_{i,j=1}^n \in \mathbb{R}^{n \times n} \quad \text{where} \quad \kappa(x,x') \mathrel{:=}\langle \varphi(x),\,\varphi(x')\rangle.

The coefficients cRnc^\star \in \mathbb{R}^n depend on the inputs only through κ\kappa, without explicit computation of φ(x)\varphi(x). If κ\kappa is inexpensive to evaluate, forming KK takes O(n2)O(n^2) kernel evaluations. A dense direct solve costs O(n3)O(n^3) operations; an iterative solve costs O(n2)O(n^2) per matrix-vector product, with the iteration count determined by conditioning and accuracy.

The fitted predictor at a new input xXx \in \mathcal{X} also uses only kernel evaluations:

β,φ(x)H=iciφ(xi),φ(x)H=iciκ(x,xi).(13.26)\langle \beta^\star,\,\varphi(x)\rangle_\mathcal{H}= \langle \sum_i c_i^\star \varphi(x_i),\,\varphi(x)\rangle_\mathcal{H}= \sum_i c_i^\star \kappa(x,x_i). \tag{13.26}

13.5.2 Kernel Design

One can also start directly from a kernel κ(x,x)\kappa(x,x') rather than an explicit feature map φ\varphi. This is often convenient because kernels can be designed through their geometric properties and combined, for example by addition. The required condition is that every Gram matrix (κ(xi,xj))i,j(\kappa(x_i,x_j))_{i,j} be symmetric positive semidefinite. Such kernels are commonly called positive definite kernels; the condition is equivalent to the existence of a Hilbert-space feature map generating the kernel.

The underlying input space need not be Euclidean.

When using the linear kernel κ(x,y)=x,y\kappa(x,y)=\langle x,\,y\rangle, one retrieves the linear models studied in the previous section, and the lifting is trivial φ(x)=x\varphi(x)=x.

A family of popular kernels are polynomial ones, κ(x,x)=(x,x+c)a\kappa(x,x') = (\langle x,\,x\prime\rangle+c)^a for aNa \in \mathbb{N}^* and c>0c>0, which corresponds to a lifting in finite dimension. For instance, for a=2a=2 and p=2p=2, one has a lifting in dimension 6

κ(x,x)=(x1x1+x2x2+c)2=φ(x),φ(x)whereφ(x)=(x12,x22,2x1x2,2cx1,2cx2,c)R6.\kappa(x,x') = \left( x_1x_1'+x_2x_2' + c \right)^2 = \langle \varphi(x),\,\varphi(x')\rangle \quad \text{where} \quad \varphi(x)=(x_1^2,x_2^2,\sqrt{2}x_1x_2,\sqrt{2c}x_1,\sqrt{2c}x_2,c)^* \in \mathbb{R}^6.

A widely used choice on Euclidean spaces is the Gaussian kernel

κ(x,y):=e ⁣xy ⁣22σ2.(13.27)\kappa(x,y) \mathrel{:=}e^{-\frac{|\!| x-y |\!|^2}{2\sigma^2}} . \tag{13.27}

The bandwidth σ>0\sigma>0 controls the locality of the model and is typically tuned by cross-validation. The Gaussian kernel has the infinite-dimensional feature map φ(x)(t)=(2/(πσ2))p/4exp( ⁣xt ⁣2/σ2)L2(Rp)\varphi(x)(t)=(2/(\pi\sigma^2))^{p/4}\exp(-|\!| x-t |\!|^2/\sigma^2)\in L^2(\mathbb{R}^p).

Another related popular kernel is the Laplacian kernel exp( ⁣xy ⁣/σ)\exp(-|\!| x-y |\!|/\sigma).

More generally, Bochner’s theorem states that a continuous translation-invariant kernel κ(x,x)=k(xx)\kappa(x,x')=k(x-x') on Rp\mathbb{R}^p is positive definite if and only if kk is the Fourier transform of a finite nonnegative measure. If this measure has an integrable density, a feature map can be built from the square root of that density. When kk is integrable and its Fourier transform is an integrable function, the condition is k^0\hat k\geqslant 0; strict positivity is not necessary.

Figure 13.20 shows an example of regression using a Gaussian kernel.

Figure 13.20. Regression using a Gaussian kernel.

Kernel on non-Euclidean spaces.

On a general input space X\mathcal{X}, a real kernel κ\kappa must produce a symmetric positive semidefinite Gram matrix K=(κ(xi,xj))i,jK=(\kappa(x_i,x_j))_{i,j} for every finite collection of inputs. Equivalently, there is a Hilbert space H\mathcal{H} and a feature map φ:XH\varphi:\mathcal{X}\rightarrow \mathcal{H} such that κ(x,x)=φ(x),φ(x)H\kappa(x,x')=\langle \varphi(x),\,\varphi(x')\rangle_\mathcal{H}.

For instance, if X=P(M)\mathcal{X}= \mathcal{P}(\mathcal{M}) is the set of measurable sets of finite measure in a measure space (M,μ)(\mathcal{M},\mu), one can define κ(A,B)=μ(AB)\kappa(A,B) = \mu(A \cap B) which corresponds to the lifting φ(A)=1A\varphi(A)=1_A so that φ(A),φ(B)=1A(x)1B(x)dμ(x)=μ(AB)\langle \varphi(A),\,\varphi(B)\rangle = \int 1_A(x) 1_B(x)\mathrm{d}\mu(x) = \mu(A \cap B).

Kernels can also be defined on strings and graphs, although their construction is more involved.

When κ(x,x)>0\kappa(x,x)>0 for every input under consideration, the kernel can be normalized to have a unit diagonal. For a translation-invariant kernel on Rp\mathbb{R}^p, the diagonal equals the constant k(0)k(0), so normalization only requires division by k(0)>0k(0)>0. This corresponds to replacing φ(x)\varphi(x) by φ(x)/ ⁣φ(x) ⁣H\varphi(x)/|\!| \varphi(x) |\!|_\mathcal{H} and thus replacing κ(x,x)\kappa(x,x') by κ(x,x)κ(x,x)κ(x,x)\frac{\kappa(x,x')}{\sqrt{\kappa(x,x)}\sqrt{\kappa(x',x')}}.

13.5.3 General Case

The least-squares result extends to other losses under the assumptions below. With a squared Hilbert-space norm penalty, the minimizer belongs to a subspace generated by the data, of dimension at most nn. This representer theorem reduces the problem to finitely many coefficients even when the feature space H\mathcal{H} is infinite dimensional.

Equation (13.29) places the minimizer in a subspace of dimension at most nn, spanned by the observed feature vectors φ(xi)\varphi(x_i).

The potentially infinite-dimensional problem (13.28) becomes the finite-dimensional problem (13.30). A dense first-order iteration costs O(n2)O(n^2) once the kernel matrix is available. A low-rank approximation KΦ~Φ~K \approx \tilde\Phi^* \tilde \Phi can reduce this cost further by introducing a smaller approximate feature space.

For classification applications, one can use for \ell a hinge or a logistic loss function, and then the decision boundary is computed following (13.26) using kernel evaluations only as

sign(β,φ(x)H)=sign(iciκ(x,xi)).\mathop{\mathrm{sign}}(\langle \beta^\star,\,\varphi(x)\rangle_\mathcal{H}) = \mathop{\mathrm{sign}}(\sum_i c_i^\star \kappa(x,x_i)).

Figure 13.21 illustrates a nonlinear decision boundary in two dimensions. The decision rule is linear in the feature space H\mathcal{H}; evaluating it through the nonlinear feature map produces a curved boundary in the input space.

Figure 13.21. Nonlinear classification using a Gaussian kernel.

Nearest-neighbor classification (Section 13.4.1) and regression can likewise use distances in feature space, computed entirely from the kernel:

 ⁣φ(xi)φ(xj) ⁣H2=κ(xi,xi)+κ(xj,xj)2κ(xi,xj).|\!| \varphi(x_i)-\varphi(x_j) |\!|_\mathcal{H}^2 = \kappa(x_i,x_i)+\kappa(x_j,x_j) - 2 \kappa(x_i,x_j).

13.6 Probably Approximately Correct Learning

This section introduces Probably Approximately Correct (PAC) learning, which studies generalization guarantees under explicit complexity and sampling assumptions. Distribution-free bounds avoid further restrictions on the data distribution. The main reference (and in particular the proofs of the mentioned results) for this section is the book “Foundations of Machine Learning” by Mehryar Mohri, Afshin Rostamizadeh, and Ameet Talwalkar https://cs.nyu.edu/~mohri/mlbook/.

Assume the observations D:=(xi,yi)i=1n\mathcal{D}\mathrel{:=}(x_i,y_i)_{i=1}^n are independent and identically distributed copies of a random pair (X,Y)(X,Y) taking values in X×Y\mathcal{X}\times\mathcal{Y}. From this sample, we seek a predictor f:XYf : \mathcal{X}\rightarrow \mathcal{Y} with risk close to the smallest achievable value:

L(f):=E((Y,f(X)))=X×Y(y,f(x))dPX,Y(x,y)L(f) \mathrel{:=}\mathbb{E}( \ell(Y,f(X)) ) = \int_{\mathcal{X}\times \mathcal{Y}} \ell(y,f(x)) \mathrm{d}\mathbb{P}_{X,Y}(x,y)

where :Y×YR\ell : \mathcal{Y}\times \mathcal{Y}\rightarrow \mathbb{R} is some loss function.

To estimate this minimizer, we select a class of functions F\mathcal{F} and minimize the empirical risk

f^argminfF  L^(f):=1ni=1n(yi,f(xi)).\hat f \in \underset{f \in \mathcal{F}}{\mathop{\mathrm{argmin}}}\; \hat L(f) \mathrel{:=}\frac{1}{n} \sum_{i=1}^n \ell(y_i,f(x_i)).

We assume a measurable minimizer exists. It is random because it depends on the sample D\mathcal{D}.

PAC learning seeks a bound on the excess risk L(f^)inf(L)0L(\hat f)-\inf(L)\geqslant 0 that holds with probability at least 1δ1-\delta. The bound depends on the sample size nn and confidence parameter δ\delta. For the excess risk to vanish, the approximation class must become sufficiently rich while its statistical complexity remains controlled. Quantitative approximation rates require distributional assumptions, although some consistency results hold without them.

13.6.1 Nonparametric Models and Calibration

If F\mathcal{F} contains all measurable functions, a minimizer ff^\star of LL is called a Bayes estimator: it achieves the smallest possible population risk.

Risk decomposition

Denoting

α(zx):=EY((Y,z)X=x)=Y(y,z)dPYX(yx)\alpha(z|x) \mathrel{:=}\mathbb{E}_Y(\ell(Y,z)|X=x) = \int_\mathcal{Y}\ell(y,z)\mathrm{d}\mathbb{P}_{Y|X}(y|x)

the average loss of predicting zYz\in\mathcal{Y} at input xXx\in\mathcal{X}, the risk decomposes as

L(f)=X[Y(y,f(x))dPYX(yx)]dPX(x)=Xα(f(x)x)dPX(x)L(f) = \int_\mathcal{X}\left[ \int_\mathcal{Y}\ell(y,f(x)) \mathrm{d}\mathbb{P}_{Y|X}(y|x) \right] \mathrm{d}\mathbb{P}_X(x) = \int_\mathcal{X}\alpha(f(x)|x) \mathrm{d}\mathbb{P}_X(x)

Consequently, ff^\star can be chosen separately at each input xx by solving

f(x)=argminz  α(zx).f^\star(x) = \underset{z}{\mathop{\mathrm{argmin}}}\; \alpha(z|x).

Calibration in the classification setup

We would like the classifier sign(f)\mathop{\mathrm{sign}}(f^\star) to agree with a Bayes classifier for the 0–1 loss, namely sign(2η1)\mathop{\mathrm{sign}}(2\eta-1) away from ties. This property is called classification calibration. It does not require the scores ff^\star and 2η12\eta-1 themselves to agree. The following result characterizes calibration for finite convex margin losses.

Both hinge and logistic loss satisfy this calibration criterion.

Let LΓL_\Gamma be the risk for (y,z)=Γ(yz)\ell(y,z)=\Gamma(-yz) and let L01L_{0\text{--}1} be classification risk, with a fixed tie-breaking convention. Quantitative calibration bounds have the form

0L01(signf)infL01Ψ(LΓ(f)infLΓ)(13.31)0 \leqslant L_{0\text{--}1}(\mathop{\mathrm{sign}}f)-\inf L_{0\text{--}1} \leqslant\Psi( L_{\Gamma}(f) - \inf L_{\Gamma} ) \tag{13.31}

for some increasing function Ψ:R+R+\Psi : \mathbb{R}^+ \rightarrow \mathbb{R}^+ satisfying Ψ(0)=0\Psi(0)=0. Such a control ensures in particular that if ff^\star minimizes LΓL_{\Gamma}, its induced classifier has Bayes-optimal 0–1 risk. At η=1/2\eta=1/2, either class is optimal; away from ties, its sign agrees almost surely with that of 2η12\eta-1.

For hinge loss, the calibration bound holds with Ψ(r)=r\Psi(r)=r. For logistic loss, it holds with Ψ(s)=2s\Psi(s)=\sqrt{2s}.

13.6.2 PAC bounds

Approximation–estimation decomposition.

For a class F\mathcal{F} of functions, the excess risk of the empirical estimator

f^argminfF  L^(f)\hat f \in \underset{f \in \mathcal{F}}{\mathop{\mathrm{argmin}}}\; \hat L(f)

decomposes into a random estimation error and a deterministic approximation error:

L(f^)infL=[L(f^)infFL]+A(F)whereA(F):=[infFLinfL].(13.32)L(\hat f) - \inf L = \Big[ L(\hat f) - \inf_{\mathcal{F}} L \Big] + \mathcal{A}(\mathcal{F}) \quad \text{where} \quad \mathcal{A}(\mathcal{F}) \mathrel{:=}\Big[ \inf_{\mathcal{F}} L - \inf L \Big]. \tag{13.32}

This separates the effects of sampling and model approximation.

Enlarging a nested class F\mathcal{F} reduces approximation error but typically increases the estimation-error bound. Choose the class size as a function of nn to balance these effects and avoid overfitting.

Approximation error.

A quantitative approximation bound requires assumptions on ff^\star. No-free-lunch results rule out a uniform distribution-free approximation rate over all measurable targets.

The following example illustrates such a bound.

Estimation error.

Concentration inequalities control sampling fluctuations, while a bound on the complexity of F\mathcal{F} makes this control uniform over the model class.

The estimation error is controlled by uniform deviations between LL and L^\hat L. Let gFg\in\mathcal{F} attain infFL\inf_{\mathcal{F}}L, assuming for simplicity that such a minimizer exists. Then

L(f^)infFL=[L(f^)L^(f^)]+[L^(f^)L^(g)]+[L^(g)L(g)]2supfFL^(f)L(f)(13.33)L(\hat f) - \inf_{\mathcal{F}} L = \Big[L(\hat f) - \hat L(\hat f)\Big] + \Big[\hat L(\hat f) - \hat L(g)\Big] + \Big[\hat L(g)-L(g)\Big] \leqslant 2 \sup_{f \in \mathcal{F}}|\hat L(f) - L(f)| \tag{13.33}

since L^(f^)L^(g)0\hat L(\hat f) - \hat L(g) \leqslant 0.

Define the two one-sided deviations

Δ+(D)=supfF(L(f)L^(f)),Δ(D)=supfF(L^(f)L(f)).\Delta_+(\mathcal{D})=\sup_{f\in\mathcal{F}}(L(f)-\hat L(f)),\qquad \Delta_-(\mathcal{D})=\sup_{f\in\mathcal{F}}(\hat L(f)-L(f)).

The preceding decomposition gives the sharper bound L(f^)infFLΔ++ΔL(\hat f)-\inf_\mathcal{F}L\leqslant\Delta_++\Delta_-. Assume all suprema below are measurable (or use outer expectations).

To bound EDΔ±(D)\mathbb{E}_\mathcal{D}\Delta_\pm(\mathcal{D}), we need to control the complexity of F\mathcal{F}. VC dimension gives one approach, but for norm-constrained linear models it can yield loose bounds that depend on the ambient dimension. Rademacher complexity gives a finer measure for a class G\mathcal{G} of functions from X×Y\mathcal{X}\times \mathcal{Y} to R\mathbb{R}:

Rn(G):=Eε,D[supgG1ni=1nεig(xi,yi)]\mathcal{R}_n(\mathcal{G}) \mathrel{:=}\mathbb{E}_{\varepsilon,\mathcal{D}}\Big[ \sup_{g \in \mathcal{G}} \frac{1}{n}\sum_{i=1}^n \varepsilon_i g(x_i,y_i) \Big]

where εi\varepsilon_i, independent of the data, are independent Rademacher random variables (i.e. P(εi=±1)=1/2\mathbb{P}(\varepsilon_i = \pm 1) = 1/2). The quantity Rn(G)\mathcal{R}_n(\mathcal{G}) depends on the distribution of (X,Y)(X,Y).

Apply this complexity measure to the loss class G=[F]\mathcal{G}= \ell[\mathcal{F}], defined by

[F]:={(x,y)X×Y(y,f(x))  ;  fF},\ell[\mathcal{F}] \mathrel{:=} \left\{ (x,y) \in \mathcal{X}\times \mathcal{Y}\mapsto \ell(y,f(x)) \;;\; f \in \mathcal{F} \right\} ,

Symmetrization gives the following bounds.

Combining (13.32), (13.33), and Propositions 13.15 and 13.16 gives the following result.