Simple Algorithm
Machine Learning · Descent · 24 min

The Math Toolkit

Vectors, matrices, probability and derivatives you will use everywhere.

Machine learning is written in four languages: vectors and matrices for data, derivatives for learning, probability for uncertainty, and logarithms for turning products into sums. This lesson gives you each in working form, with the one derivation or picture that makes it usable, and derives the gradient that trains a linear model.

What you’ll learn

  • Write a dataset as a design matrix and translate sums over examples into matrix products such as XwX\mathbf w, X⊤yX^\top\mathbf y and X⊤XX^\top X.
  • Interpret the eigenvalues and eigenvectors of a symmetric matrix, and read a covariance matrix's principal directions from them.
  • Derive the gradient of the squared loss of a linear model with the chain rule, and the normal equations from it.
  • Compute expectations, variances and posteriors with Bayes' rule, and explain why learning works with log-probabilities.

Data as vectors, datasets as matrices

An example with dd features is a vector x∈Rd\mathbf x\in\R^d, and nn examples stacked as rows form the design matrix X∈Rn×dX\in\R^{n\times d}, with the targets in y∈Rn\mathbf y\in\R^n. Almost every formula in this course is a sum over examples, and almost every sum over examples is a matrix product. Seeing one in the other is the first skill of the toolkit.

Sum over examplesMatrix formShapeMeaning
y^i=∑jxijwj\hat y_i=\sum_jx_{ij}w_j for every iiXwX\mathbf wn×1n\times1the predictions of a linear model
∑iyi xi\sum_iy_i\,\mathbf x_iX⊤yX^\top\mathbf yd×1d\times1how strongly each feature moves with the target
∑ixixi⊤\sum_i\mathbf x_i\mathbf x_i^\topX⊤XX^\top Xd×dd\times dsums of products of every pair of features
xi⊤xk\mathbf x_i^\top\mathbf x_k for all pairs i,ki,kXX⊤XX^\topn×nn\times nthe Gram matrix: similarities between examples
1n∑i(xi−xˉ)(xi−xˉ)⊤\frac1n\sum_i(\mathbf x_i-\bar{\mathbf x})(\mathbf x_i-\bar{\mathbf x})^\top1nXc⊤Xc\frac1nX_c^\top X_cd×dd\times dthe sample covariance matrix (XcX_c has centered columns)
Here xi⊤\mathbf x_i^\top is row ii of XX, xijx_{ij} its jj-th feature and xˉ=1n∑ixi\bar{\mathbf x}=\frac1n\sum_i\mathbf x_i the mean example. Translating a sum into a product is not only shorter: libraries execute products with optimized linear-algebra routines, often hundreds of times faster than explicit Python loops.

The dot product a⊤b=∑jajbj\mathbf a^\top\mathbf b=\sum_ja_jb_j is also geometry: a⊤b=∥a∥∥b∥cos⁡θ\mathbf a^\top\mathbf b=\norm{\mathbf a}\norm{\mathbf b}\cos\theta, where θ\theta is the angle between the vectors. So the cosine similarity a⊤b/(∥a∥∥b∥)\mathbf a^\top\mathbf b/(\norm{\mathbf a}\norm{\mathbf b}) measures alignment regardless of length, which is how embeddings are compared, and the Cauchy–Schwarz inequality ∣a⊤b∣≤∥a∥∥b∥\abs{\mathbf a^\top\mathbf b}\le\norm{\mathbf a}\norm{\mathbf b} follows at once. Norms measure size: the Euclidean ∥a∥2=∑jaj2\norm{\mathbf a}_2=\sqrt{\sum_ja_j^2}, the ∥a∥1=∑j∣aj∣\norm{\mathbf a}_1=\sum_j\abs{a_j} behind the lasso, and ∥a∥∞=max⁡j∣aj∣\norm{\mathbf a}_\infty=\max_j\abs{a_j}. Distances expand into dot products: ∥a−b∥2=∥a∥2+∥b∥2−2 a⊤b\norm{\mathbf a-\mathbf b}^2=\norm{\mathbf a}^2+\norm{\mathbf b}^2-2\,\mathbf a^\top\mathbf b.

Check your understanding

XX holds n=10,000n=10{,}000 examples of d=50d=50 features. What are the shape and the meaning of X⊤XX^\top X?

  1. 50×150\times1: the sum of each feature
  2. 10,000×10,00010{,}000\times10{,}000: the dot product of every pair of examples
  3. It is undefined, because XX is not square
  4. 50×5050\times50: entry (j,k)(j,k) is ∑ixijxik\sum_ix_{ij}x_{ik}, the product of features jj and kk summed over all examples
Show the answer

D. 50×5050\times50: entry (j,k)(j,k) is ∑ixijxik\sum_ix_{ij}x_{ik}, the product of features jj and kk summed over all examples

X⊤X^\top is 50×10,00050\times10{,}000 and XX is 10,000×5010{,}000\times50, so the product is 50×5050\times50, with entry (j,k)=∑ixijxik(j,k)=\sum_ix_{ij}x_{ik}. It equals ∑ixixi⊤\sum_i\mathbf x_i\mathbf x_i^\top, a sum of outer products, and for centered data it is nn times the covariance matrix. Its size depends on the number of features, not of examples, which keeps the normal equations cheap for tall datasets.

Matrices as maps, and their eigenvectors

A matrix also acts: AxA\mathbf x is a combination of AA's columns with weights xjx_j, and x↦Ax\mathbf x\mapsto A\mathbf x is a linear map that can stretch, rotate and project. An eigenvector is a direction the map only stretches, Av=λvA\mathbf v=\lambda\mathbf v, by a factor λ\lambda, its eigenvalue. For the symmetric matrices that fill machine learning (covariances, Gram matrices, Hessians), the spectral theorem guarantees real eigenvalues and an orthonormal basis of eigenvectors, so A=QΛQ⊤A=Q\Lambda Q^\top: in eigenvector coordinates, AA simply rescales each axis. The Convergence lesson on linear algebra proves it.

A=(2112):A(11)=3(11),A(1−1)=1⋅(1−1)A=\begin{pmatrix}2&1\\1&2\end{pmatrix}:\qquad A\begin{pmatrix}1\\1\end{pmatrix}=3\begin{pmatrix}1\\1\end{pmatrix},\qquad A\begin{pmatrix}1\\-1\end{pmatrix}=1\cdot\begin{pmatrix}1\\-1\end{pmatrix}
Two invariants check the eigenvalues: they sum to the trace (3+1=2+23+1=2+2) and multiply to the determinant (3⋅1=2⋅2−1⋅13\cdot1=2\cdot2-1\cdot1). The normalized eigenvectors (1,1)/2(1,1)/\sqrt2 and (1,−1)/2(1,-1)/\sqrt2 are orthogonal, as the spectral theorem promises.

For a covariance matrix SS, the quadratic form v⊤Sv=1n∑i(v⊤(xi−xˉ))2\mathbf v^\top S\mathbf v=\frac1n\sum_i\big(\mathbf v^\top(\mathbf x_i-\bar{\mathbf x})\big)^2 is the variance of the data projected onto a unit vector v\mathbf v. It is never negative, so SS is positive semidefinite, and it is largest along the top eigenvector, where it equals the top eigenvalue λ1\lambda_1. That direction is the first principal component; PCA keeps the top few.

Predict before you look

Two-dimensional data have covariance matrix (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix}. What percentage of the total variance lies along the first principal component?

Show the answer

75 %

The eigenvalues are 3 and 1, and the total variance is the trace, 2+2=4=3+12+2=4=3+1. The first principal direction, (1,1)/2(1,1)/\sqrt2, carries 3/4=75%3/4=75\%; the second carries 25%. Each feature alone carries only half the total: the correlation between the two features is what concentrates the variance along the diagonal.

Derivatives, gradients and the chain rule

For a function f:Rd→Rf:\R^d\to\R, the gradient collects the partial derivatives, ∇f(w)=(∂f/∂w1,…,∂f/∂wd)\nabla f(\mathbf w)=(\partial f/\partial w_1,\dots,\partial f/\partial w_d). It gives the best linear approximation of ff near w\mathbf w: f(w+δ)≈f(w)+∇f(w)⊤δf(\mathbf w+\boldsymbol\delta)\approx f(\mathbf w)+\nabla f(\mathbf w)^\top\boldsymbol\delta. Among unit directions u\mathbf u, the rate of change ∇f⊤u\nabla f^\top\mathbf u is largest, by Cauchy–Schwarz, at u=∇f/∥∇f∥\mathbf u=\nabla f/\norm{\nabla f}, where it equals ∥∇f∥\norm{\nabla f}. The gradient points uphill, and gradient descent steps the other way, w←w−η∇f(w)\mathbf w\leftarrow\mathbf w-\eta\nabla f(\mathbf w), with a learning rate η>0\eta>0.

Models are compositions, and the chain rule differentiates compositions. In one variable, (f∘g)′(w)=f′(g(w)) g′(w)(f\circ g)'(w)=f'(g(w))\,g'(w). With vectors: if z=g(w)∈Rm\mathbf z=\mathbf g(\mathbf w)\in\R^m and L=f(z)L=f(\mathbf z), then ∇wL=Jg(w)⊤∇zf\nabla_{\mathbf w}L=J_{\mathbf g}(\mathbf w)^\top\nabla_{\mathbf z}f, where the Jacobian JgJ_{\mathbf g} is the m×dm\times d matrix of partial derivatives ∂zk/∂wj\partial z_k/\partial w_j. Backpropagation is this rule applied layer by layer, from the loss backward. Second derivatives form the Hessian ∇2f\nabla^2f, and the second-order Taylor expansion f(w+δ)≈f(w)+∇f⊤δ+12δ⊤∇2f δf(\mathbf w+\boldsymbol\delta)\approx f(\mathbf w)+\nabla f^\top\boldsymbol\delta+\tfrac12\boldsymbol\delta^\top\nabla^2f\,\boldsymbol\delta describes curvature: a twice-differentiable ff is convex exactly when its Hessian is positive semidefinite everywhere.

The gradient of the squared loss

Now the payoff. A linear model predicts y^=x⊤w\hat y=\mathbf x^\top\mathbf w (a column of ones in XX absorbs the intercept), and least squares minimizes the mean squared error over the training set:

L(w)=1n∑i=1n(yi−xi⊤w)2=1n∥y−Xw∥2L(\mathbf w)=\frac1n\sum_{i=1}^{n}\big(y_i-\mathbf x_i^\top\mathbf w\big)^2=\frac1n\norm{\mathbf y-X\mathbf w}^2
DerivationGradient and normal equations
  1. ∂∂wj(yi−xi⊤w)2=2(yi−xi⊤w)⋅(−xij)\frac{\partial}{\partial w_j}\big(y_i-\mathbf x_i^\top\mathbf w\big)^2=2\big(y_i-\mathbf x_i^\top\mathbf w\big)\cdot(-x_{ij})

    Differentiate one term with the chain rule. The inside is the residual ri=yi−xi⊤wr_i=y_i-\mathbf x_i^\top\mathbf w, and ∂ri/∂wj=−xij\partial r_i/\partial w_j=-x_{ij}:

  2. ∇w(yi−xi⊤w)2=−2 ri xi\nabla_{\mathbf w}\big(y_i-\mathbf x_i^\top\mathbf w\big)^2=-2\,r_i\,\mathbf x_i

    Collect the dd partial derivatives into a vector: each example pulls on w\mathbf w along its own input, in proportion to its residual.

  3. ∇L(w)=−2n∑i=1nri xi=2n X⊤(Xw−y)\nabla L(\mathbf w)=-\frac2n\sum_{i=1}^{n}r_i\,\mathbf x_i=\frac2n\,X^\top(X\mathbf w-\mathbf y)

    Average over the examples and use the table of the first step, ∑irixi=X⊤r\sum_ir_i\mathbf x_i=X^\top\mathbf r with r=y−Xw\mathbf r=\mathbf y-X\mathbf w:

  4. X⊤X w=X⊤y⟹w^=(X⊤X)−1X⊤yX^\top X\,\mathbf w=X^\top\mathbf y\qquad\Longrightarrow\qquad\hat{\mathbf w}=(X^\top X)^{-1}X^\top\mathbf y

    The Hessian 2nX⊤X\tfrac2nX^\top X is positive semidefinite, so LL is convex and every point where the gradient vanishes is a global minimum. Setting the gradient to zero gives the normal equations, with a unique solution when XX has full column rank:

Think first One feature, no intercept, two examples: (x,y)=(1,2)(x,y)=(1,2) and (2,3)(2,3). What is the derivative of L(w)=12[(2−w)2+(3−2w)2]L(w)=\tfrac12\big[(2-w)^2+(3-2w)^2\big] at w=0w=0, and which ww minimizes LL?

L′(w)=22[(w−2)⋅1+(2w−3)⋅2]=5w−8L'(w)=\tfrac22\big[(w-2)\cdot1+(2w-3)\cdot2\big]=5w-8, so L′(0)=−8L'(0)=-8: the loss falls as ww grows. In one dimension the normal equation reads w∑ixi2=∑ixiyiw\sum_ix_i^2=\sum_ix_iy_i, so w^=(1⋅2+2⋅3)/(1+4)=8/5=1.6\hat w=(1\cdot2+2\cdot3)/(1+4)=8/5=1.6, exactly where 5w−8=05w-8=0.

python
import numpy as np

rng = np.random.default_rng(0)
n, d = 200, 3
X = rng.normal(size=(n, d))
w_true = np.array([1.0, -2.0, 0.5])
y = X @ w_true + 0.1 * rng.normal(size=n)

w = np.zeros(d)
eta = 0.1
for t in range(500):
    grad = (2 / n) * X.T @ (X @ w - y)    # gradient of the mean squared error
    w -= eta * grad

w_exact = np.linalg.solve(X.T @ X, X.T @ y)  # the normal equations
print(np.abs(w - w_exact).max())             # agrees to machine precision

Gradient descent and the normal equations find the same minimizer. Forming and solving X⊤Xw=X⊤yX^\top X\mathbf w=X^\top\mathbf y costs about nd2+d3nd^2+d^3 operations; for many features or streaming data the gradient route scales better, and numerically careful solvers factor XX (QR or SVD) instead of forming X⊤XX^\top X, as the Convergence lesson explains.

Random variables, expectation and variance

A random variable XX assigns a number to each outcome of an experiment, with a distribution given by a probability mass function p(x)p(x) or a density. Its expectation E[X]=∑xx p(x)\E[X]=\sum_xx\,p(x) (an integral for densities) is its long-run average, and expectation is linear: E[aX+bY]=aE[X]+bE[Y]\E[aX+bY]=a\E[X]+b\E[Y] for any random variables, dependent or not. The variance Var⁡[X]=E[(X−EX)2]=E[X2]−(EX)2\Var[X]=\E[(X-\E X)^2]=\E[X^2]-(\E X)^2 measures spread, and the covariance Cov⁡[X,Y]=E[(X−EX)(Y−EY)]\Cov[X,Y]=\E[(X-\E X)(Y-\E Y)] measures how two variables move together. Independent variables have zero covariance, but zero covariance does not imply independence.

DerivationWhy averages are reliable
  1. E[Xˉ]=1n∑i=1nE[Xi]=μ\E[\bar X]=\frac1n\sum_{i=1}^{n}\E[X_i]=\mu

    Let X1,…,XnX_1,\dots,X_n be independent with mean μ\mu and variance σ2\sigma^2, and let Xˉ=1n∑iXi\bar X=\frac1n\sum_iX_i. Linearity gives its mean:

  2. Var⁡[Xˉ]=1n2∑i=1nVar⁡[Xi]=σ2n\Var[\bar X]=\frac1{n^2}\sum_{i=1}^{n}\Var[X_i]=\frac{\sigma^2}n

    Variances of independent variables add, because every cross term Cov⁡[Xi,Xk]\Cov[X_i,X_k] with i≠ki\ne k vanishes, and constants come out squared:

  3. SE(Xˉ)=σn\mathrm{SE}(\bar X)=\frac{\sigma}{\sqrt n}

    So the spread of the average, its standard error, shrinks like 1/n1/\sqrt n: four times the data halves it. The law of large numbers and the central limit theorem sharpen this, and the Convergence lesson Probability & Concentration Inequalities turns it into finite-sample guarantees.

Predict before you look

A classifier errs on 10% of a test set of 400 independent examples. Each example's error indicator is a Bernoulli variable with variance p(1−p)p(1-p). What is the standard error of the estimated error rate, in percentage points?

Show the answer

1.5 points

p(1−p)/n=0.1⋅0.9/400=0.000225=0.015\sqrt{p(1-p)/n}=\sqrt{0.1\cdot0.9/400}=\sqrt{0.000225}=0.015, or 1.5 percentage points. Two classifiers whose error rates differ by 1 point on this test set are not reliably different, and quadrupling the test set to 1,600 examples only halves the standard error, to 0.75 points.

The Gaussian N(μ,σ2)\mathcal N(\mu,\sigma^2) has density 12πσ2e−(x−μ)2/2σ2\frac1{\sqrt{2\pi\sigma^2}}e^{-(x-\mu)^2/2\sigma^2}; about 68%, 95% and 99.7% of its mass lies within 1, 2 and 3 standard deviations of the mean. In dd dimensions, the multivariate Gaussian N(μ,Σ)\mathcal N(\boldsymbol\mu,\Sigma) with a positive definite covariance Σ\Sigma has density

p(x)=1(2π)d/2det⁡(Σ)1/2exp⁡(−12(x−μ)⊤Σ−1(x−μ))p(\mathbf x)=\frac{1}{(2\pi)^{d/2}\det(\Sigma)^{1/2}}\exp\Big(-\tfrac12(\mathbf x-\boldsymbol\mu)^\top\Sigma^{-1}(\mathbf x-\boldsymbol\mu)\Big)
Its contours are ellipses whose axes are the eigenvectors of Σ\Sigma, with half-lengths proportional to λi\sqrt{\lambda_i}: the linear algebra of the second step, drawn as probability.

Conditional probability, Bayes' rule and logarithms

The probability of AA given BB is P(A∣B)=P(A∩B)/P(B)P(A\mid B)=P(A\cap B)/P(B). Writing P(A∩B)P(A\cap B) both ways, P(A∣B)P(B)=P(B∣A)P(A)P(A\mid B)P(B)=P(B\mid A)P(A), and dividing gives Bayes' rule, which turns the probability of evidence under a hypothesis into the probability of the hypothesis given the evidence:

P(H∣E)=P(E∣H) P(H)P(E),P(E)=P(E∣H) P(H)+P(E∣¬H) P(¬H)P(H\mid E)=\frac{P(E\mid H)\,P(H)}{P(E)},\qquad P(E)=P(E\mid H)\,P(H)+P(E\mid\neg H)\,P(\neg H)

Why logarithms. Learning multiplies many probabilities: the likelihood of nn independent examples is ∏ip(xi∣θ)\prod_ip(\mathbf x_i\mid\boldsymbol\theta). A thousand factors of 0.01 multiply to 10−200010^{-2000}, far below the smallest positive double-precision number (about 5×10−3245\times10^{-324}), so computers work with log⁡∏ipi=∑ilog⁡pi\log\prod_ip_i=\sum_i\log p_i instead. Because the logarithm is increasing, maximizing the log-likelihood picks the same parameters as maximizing the likelihood, and sums are what averages and gradients handle best. Exponentials go the other way: softmax turns scores zkz_k into probabilities ezk/∑jezje^{z_k}/\sum_je^{z_j}, computed stably with the log-sum-exp identity:

log⁡∑kezk=m+log⁡∑kezk−m,m=max⁡kzk\log\sum_ke^{z_k}=m+\log\sum_ke^{z_k-m},\qquad m=\max_kz_k
Subtracting the maximum makes every exponent at most 0, so nothing overflows, and the largest term is exactly e0=1e^0=1, so the sum cannot underflow to zero.

Key takeaways

  • A dataset is a design matrix X∈Rn×dX\in\R^{n\times d}, and sums over examples are matrix products: predictions XwX\mathbf w, X⊤yX^\top\mathbf y, the feature-by-feature X⊤XX^\top X and the example-by-example Gram matrix XX⊤XX^\top.
  • Dot products measure alignment, a⊤b=∥a∥∥b∥cos⁡θ\mathbf a^\top\mathbf b=\norm{\mathbf a}\norm{\mathbf b}\cos\theta. Symmetric matrices have real eigenvalues and orthonormal eigenvectors; a covariance matrix's top eigenvector is the direction of greatest variance, and its eigenvalue is that variance.
  • The gradient points uphill with slope ∥∇f∥\norm{\nabla f}, and the chain rule composes derivatives. For least squares, ∇L=2nX⊤(Xw−y)\nabla L=\tfrac2nX^\top(X\mathbf w-\mathbf y), and setting it to zero gives the normal equations X⊤Xw=X⊤yX^\top X\mathbf w=X^\top\mathbf y.
  • Expectation is linear; the mean of nn independent variables has standard deviation σ/n\sigma/\sqrt n; Bayes' rule weighs evidence by base rates.
  • Learning works with log-probabilities: logs turn products into sums, prevent underflow and leave maximizers unchanged, and the log-sum-exp identity computes softmax stably.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

At the current weights the gradient of the loss is ∇L=(3,−4)\nabla L=(3,-4). You move a short distance 0.010.01. Which direction lowers the loss fastest, and by about how much?

  1. Along (3,−4)/5(3,-4)/5, lowering the loss by about 0.050.05
  2. Along (−3,4)/5(-3,4)/5, lowering the loss by about 0.050.05
  3. Along (−3,4)/5(-3,4)/5, lowering the loss by about 0.070.07
  4. Along (0,1)(0,1), the coordinate with the largest partial derivative
Show the answer

B. Along (−3,4)/5(-3,4)/5, lowering the loss by about 0.050.05

The steepest descent direction is −∇L/∥∇L∥=(−3,4)/5-\nabla L/\norm{\nabla L}=(-3,4)/5, and to first order the loss changes by ∇L⊤δ=−∥∇L∥⋅0.01=−5⋅0.01=−0.05\nabla L^\top\boldsymbol\delta=-\norm{\nabla L}\cdot0.01=-5\cdot0.01=-0.05.

Question 2

Setting the gradient of 1n∥y−Xw∥2\frac1n\norm{\mathbf y-X\mathbf w}^2 to zero gives which equation?

  1. Xw=yX\mathbf w=\mathbf y
  2. XX⊤w=yXX^\top\mathbf w=\mathbf y
  3. X⊤Xw=X⊤yX^\top X\mathbf w=X^\top\mathbf y
  4. w=X⊤y\mathbf w=X^\top\mathbf y
Show the answer

C. X⊤Xw=X⊤yX^\top X\mathbf w=X^\top\mathbf y

∇L=2nX⊤(Xw−y)=0\nabla L=\frac2nX^\top(X\mathbf w-\mathbf y)=\mathbf 0 gives X⊤Xw=X⊤yX^\top X\mathbf w=X^\top\mathbf y: the residual y−Xw\mathbf y-X\mathbf w must be orthogonal to every column of XX. With more examples than features, Xw=yX\mathbf w=\mathbf y usually has no solution at all.

Question 3

You average nn independent measurements, each with standard deviation σ\sigma. How does the standard deviation of the average scale?

  1. σ/n\sigma/n
  2. σ/n\sigma/\sqrt n
  3. σ\sigma, unchanged
  4. σn\sigma\sqrt n
Show the answer

B. σ/n\sigma/\sqrt n

Var⁡[Xˉ]=σ2/n\Var[\bar X]=\sigma^2/n, so the standard deviation is σ/n\sigma/\sqrt n. Halving an error bar takes four times the data, a square-root law that recurs in every generalization bound of this course.

Question 4

A test with sensitivity 90% and false-positive rate 9% comes back positive for a disease with 1% prevalence. Why is the probability of disease only about 9%?

  1. Because the test is only 90% accurate
  2. Because a single test can never raise a probability above 10%
  3. Because the disease and the test result are independent
  4. Because healthy people are 99 times as numerous, so their false alarms (about 89 per 1,000 people) outnumber the true positives (about 9)
Show the answer

D. Because healthy people are 99 times as numerous, so their false alarms (about 89 per 1,000 people) outnumber the true positives (about 9)

P(D∣+)=0.9⋅0.01/(0.9⋅0.01+0.09⋅0.99)=0.009/0.0981≈9.2%P(D\mid+)=0.9\cdot0.01/(0.9\cdot0.01+0.09\cdot0.99)=0.009/0.0981\approx9.2\%. The prior multiplies the likelihood: a small error rate applied to a huge healthy population produces many false positives.

Question 5

For a covariance matrix SS, what does its largest eigenvalue λ1\lambda_1 equal?

  1. The variance of the data projected onto the top eigenvector, the largest projected variance over all unit directions
  2. The largest variance of any single feature
  3. The determinant of SS
  4. The number of features
Show the answer

A. The variance of the data projected onto the top eigenvector, the largest projected variance over all unit directions

For a unit vector v\mathbf v, v⊤Sv\mathbf v^\top S\mathbf v is the variance along v\mathbf v, and its maximum over unit vectors is λ1\lambda_1, attained at the top eigenvector. It is at least every diagonal entry (a single feature's variance) and larger when features are correlated: for (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix}, λ1=3>2\lambda_1=3>2.

Go deeper

Further reading

  • M. P. Deisenroth, A. A. Faisal & C. S. Ong, Mathematics for Machine Learning (Cambridge University Press, 2020).
  • I. Goodfellow, Y. Bengio & A. Courville, Deep Learning (MIT Press, 2016), chapters 2–4.
  • L. Wasserman, All of Statistics (Springer, 2004), chapters 1–5.