Mock midterm 1

Seven problems, 60 points, 120 minutes: two minutes per point. Written by Claude from Lectures 1–7, HW1, HW2, Quiz 1 and Quiz 2. Every number was recomputed with numpy.

How to sit this mock. Print nothing, open nothing. Put a timer on 120 minutes, work every part on paper, and only then open the answers. The real exam gives you the formula sheet (lectures/ADA -Midterm1-CheatSheet.pdf) but no cheat sheet of your own, no graphical calculator, and no credit for a final answer without the steps that led to it.

Teal = an added hint or marking note. Amber = a mistake the TA flagged after Quiz 2. Each answer sits in a dropdown; the "How did it go?" buttons appear when the page is opened through the Study app.

ProblemPointsMinutesTestsModelled on
P1 Vectors816dot product, norms, angle, projection, distancesQuiz 1 Q1 · HW1 Q1–2
P2 Random variables816pmf, cdf, pdf, probabilities, mean, variance, medianHW1 Q4–5
P3 Two attributes1224mean vector, covariance matrix, correlation, eigenvalues, normal probabilityQuiz 1 Q2 · HW1 Q3
P4 PCA1224centre, covariance, eigenvectors, projection, reconstruction errorHW2 Q1–2 · Quiz 2 P1
P5 Kernels1020kernel matrix, feature map, norms and distances, centring, kernel PCAQuiz 2 P2 · HW2 Q3
P6 Regression612slope, intercept, residuals, SSE, RMSEL7 s10–13 · HW2 Q6
P7 Concepts48four one-line explanationsTA announcement

Part 1

Vectors and probability

Short problems first. Bank these points fast and cleanly.

Problem 1 · Two vectors in \(\mathbb R^3\) (8 points)

Everything in this problem comes from three formulas: the dot product, the Euclidean norm, and the projection formula. The marks are for showing each one applied.

Let

\[ \mathbf u = \begin{bmatrix} 3 \\ 0 \\ 4 \end{bmatrix}, \qquad \mathbf v = \begin{bmatrix} 4 \\ 3 \\ 0 \end{bmatrix} \]
(a) Compute \(\mathbf u^T\mathbf v\), \(\|\mathbf u\|\) and \(\|\mathbf v\|\).
  1. \[ \mathbf u^T\mathbf v = 3(4) + 0(3) + 4(0) = 12 \]
  2. \[ \|\mathbf u\| = \sqrt{9 + 0 + 16} = 5 \]
  3. \[ \|\mathbf v\| = \sqrt{16 + 9 + 0} = 5 \]

Marks: 1 for the dot product, 1 for both norms.

(b) Find the cosine similarity and the angle \(\theta\) between them, in degrees.
  1. \[ \cos\theta = \frac{\mathbf u^T\mathbf v}{\|\mathbf u\|\,\|\mathbf v\|} = \frac{12}{25} = 0.48 \]
  2. \[ \theta = \cos^{-1}(0.48) \approx 61.3^\circ \]

The vectors have the same length, so the cosine is small-ish and the angle is noticeably larger than 45°. Positive cosine means they lean the same way; 0 would mean orthogonal.

(c) Compute the projection of \(\mathbf u\) onto \(\mathbf v\), then show that what is left over, \(\mathbf u - \mathrm{proj}_{\mathbf v}(\mathbf u)\), is orthogonal to \(\mathbf v\).
  1. \[ \mathrm{proj}_{\mathbf v}(\mathbf u) = \frac{\mathbf u^T\mathbf v}{\mathbf v^T\mathbf v}\,\mathbf v = \frac{12}{25}\begin{bmatrix} 4 \\ 3 \\ 0 \end{bmatrix} \]
  2. \[ \mathrm{proj}_{\mathbf v}(\mathbf u) = \begin{bmatrix} 1.92 \\ 1.44 \\ 0 \end{bmatrix} \]
  3. \[ \mathbf u - \mathrm{proj}_{\mathbf v}(\mathbf u) = \begin{bmatrix} 1.08 \\ -1.44 \\ 4 \end{bmatrix} \]
  4. \[ (1.08)(4) + (-1.44)(3) + (4)(0) = 4.32 - 4.32 = 0 \quad\checkmark \]

The post-quiz note in your notebook says you memorised this formula wrong once. The denominator is \(\|\mathbf v\|^2 = \mathbf v^T\mathbf v\), the squared length of the vector you project onto, and the result is a multiple of \(\mathbf v\), never of \(\mathbf u\).

(d) Find the Euclidean distance and the city-block (\(L_1\)) distance between \(\mathbf u\) and \(\mathbf v\).
  1. \[ \mathbf u - \mathbf v = \begin{bmatrix} -1 \\ -3 \\ 4 \end{bmatrix} \]
  2. \[ \|\mathbf u - \mathbf v\|_2 = \sqrt{1 + 9 + 16} = \sqrt{26} \approx 5.10 \]
  3. \[ \|\mathbf u - \mathbf v\|_1 = 1 + 3 + 4 = 8 \]

The Euclidean distance can also come from the cosine rule: \(\|\mathbf u-\mathbf v\|^2 = 25 + 25 - 2(12) = 26\). Same answer, and a good way to catch an arithmetic slip.

Problem 2 · A discrete and a continuous random variable (8 points)

Part one is a pmf you sum, part two is a pdf you integrate. In both, the cdf is the tool for every probability question, and the median is where the cdf reaches one half.

A discrete random variable \(X\) has

\[ p(x) = \frac{x}{10}, \qquad x \in \{1, 2, 3, 4\} \]

A continuous random variable \(Y\) has density

\[ f(y) = c\,y, \qquad 0 \le y \le 2 \]
(a) Verify that \(p(x)\) is a valid pmf and write down the cdf \(F(x)\) at \(x = 1, 2, 3, 4\).
  1. Every value is between 0 and 1, and \[ \tfrac{1}{10} + \tfrac{2}{10} + \tfrac{3}{10} + \tfrac{4}{10} = 1 \]
  2. \[ F(1) = 0.1,\quad F(2) = 0.3,\quad F(3) = 0.6,\quad F(4) = 1 \]

\(F(x) = 0\) for \(x \lt 1\), it is a staircase that jumps at 1, 2, 3, 4, and it stays at 1 for \(x \ge 4\).

(b) Compute \(P(1.5 \le X \le 3.5)\).
  1. Only \(x = 2\) and \(x = 3\) fall in the interval: \[ P(1.5 \le X \le 3.5) = F(3) - F(1) = 0.6 - 0.1 = 0.5 \]

\(F(1.5) = F(1)\) because nothing happens between 1 and 2. Writing \(F(3) - F(1.5)\) is also right; writing \(F(3.5) - F(1.5)\) with made-up values is the common slip.

(c) Compute \(E[X]\) and \(\mathrm{Var}(X)\).
  1. \[ E[X] = \frac{1 + 4 + 9 + 16}{10} = 3 \]
  2. \[ E[X^2] = \frac{1 + 8 + 27 + 64}{10} = 10 \]
  3. \[ \mathrm{Var}(X) = E[X^2] - (E[X])^2 = 10 - 9 = 1 \]
(d) Find \(c\) and the cdf \(F(y)\) of \(Y\).
  1. \[ \int_0^2 c\,y\,dy = c\left[\frac{y^2}{2}\right]_0^2 = 2c = 1 \]
  2. \[ c = \tfrac12 \]
  3. \[ F(y) = \int_0^y \frac{t}{2}\,dt = \frac{y^2}{4}, \qquad 0 \le y \le 2 \]

\(F(y) = 0\) below 0 and \(F(y) = 1\) above 2. Say so: the piecewise form is part of the answer.

(e) Compute \(P(1 \le Y \le 2)\) and the median of \(Y\).
  1. \[ P(1 \le Y \le 2) = F(2) - F(1) = 1 - \tfrac14 = 0.75 \]
  2. Median: solve \(F(\nu) = \tfrac12\): \[ \frac{\nu^2}{4} = \frac12 \;\Rightarrow\; \nu = \sqrt 2 \approx 1.414 \]

The mean is \(\int_0^2 y \cdot \tfrac{y}{2}\,dy = \tfrac43 \approx 1.333\). Median and mean differ because the density is not symmetric.

Part 2

Covariance, PCA, kernels

The core of the exam. Quiz 1 and Quiz 2 were both drawn from here.

Problem 3 · Two attributes, five samples (12 points)

This is Quiz 1 Question 2 with new numbers: build the covariance matrix from centred columns, read correlation off it, then find its eigenvalues. The normal-probability part comes from HW1 Q3.

A random sample of size \(n = 5\) from two random variables:

\[ X = (1, 2, 3, 4, 5), \qquad Y = (1, 3, 2, 5, 4) \]

Use \(\tfrac1n\) in all variances and covariances. You may use \(\Phi(1.41) = 0.9207\) and \(\Phi(0.71) = 0.7611\).

(a) Find the sample mean vector \(\hat{\boldsymbol\mu}\) and the medians of \(X\) and \(Y\).
  1. \[ \bar X = \tfrac{15}{5} = 3, \qquad \bar Y = \tfrac{15}{5} = 3 \]
  2. \[ \hat{\boldsymbol\mu} = \begin{bmatrix} 3 \\ 3 \end{bmatrix} \]
  3. Sort \(Y\): \((1, 2, 3, 4, 5)\). With \(n = 5\) odd, the median is the 3rd value: \[ \operatorname{median}(X) = 3, \qquad \operatorname{median}(Y) = 3 \]
(b) Find the sample covariance matrix \(\hat\Sigma\).
  1. Centre: \[ X - \bar X = (-2, -1, 0, 1, 2), \qquad Y - \bar Y = (-2, 0, -1, 2, 1) \]
  2. \[ \hat\sigma_{XX} = \tfrac15(4 + 1 + 0 + 1 + 4) = 2 \]
  3. \[ \hat\sigma_{YY} = \tfrac15(4 + 0 + 1 + 4 + 1) = 2 \]
  4. \[ \hat\sigma_{XY} = \tfrac15\big(4 + 0 + 0 + 2 + 2\big) = 1.6 \]
  5. \[ \hat\Sigma = \begin{bmatrix} 2 & 1.6 \\ 1.6 & 2 \end{bmatrix} \]

Marks: 1 for the centred columns, 1 for the two variances, 1 for the covariance placed symmetrically.

(c) Compute the correlation coefficient and say in one sentence what it tells you.
  1. \[ r = \frac{\hat\sigma_{XY}}{\sqrt{\hat\sigma_{XX}\,\hat\sigma_{YY}}} = \frac{1.6}{\sqrt{2 \cdot 2}} = 0.8 \]
  2. A strong positive linear relationship: when \(X\) is above its mean, \(Y\) tends to be above its mean too.
(d) Find the eigenvalues of \(\hat\Sigma\), a unit eigenvector for the larger one, and the fraction of the total variance it captures.
  1. For \(\begin{bmatrix} a & b \\ b & a \end{bmatrix}\) the eigenvalues are \(a \pm b\): \[ \lambda_1 = 2 + 1.6 = 3.6, \qquad \lambda_2 = 2 - 1.6 = 0.4 \]
  2. Check: \[ \lambda_1 + \lambda_2 = 4 = \operatorname{tr}\hat\Sigma \]
  3. \((\hat\Sigma - 3.6 I)\mathbf v = 0\) gives \(-1.6 v_1 + 1.6 v_2 = 0\), so \(v_1 = v_2\): \[ \mathbf v_1 = \tfrac{1}{\sqrt2}\begin{bmatrix} 1 \\ 1 \end{bmatrix} \]
  4. \[ \frac{\lambda_1}{\lambda_1 + \lambda_2} = \frac{3.6}{4} = 0.9 = 90\% \]

Then \(a \pm b\) does not apply. Use the characteristic equation \(\lambda^2 - \operatorname{tr}(\hat\Sigma)\lambda + \det(\hat\Sigma) = 0\) and the quadratic formula, as in Problem 4.

(e) Assume \(X \sim N(\bar X, \hat\sigma_{XX})\). Find \(P(X \ge 5)\) and \(P(X \le 2)\).
  1. \[ \sigma_X = \sqrt 2 \approx 1.414 \]
  2. \[ z = \frac{5 - 3}{1.414} = 1.41 \]
  3. \[ P(X \ge 5) = 1 - \Phi(1.41) = 1 - 0.9207 = 0.0793 \]
  4. \[ z = \frac{2 - 3}{1.414} = -0.71 \]
  5. \[ P(X \le 2) = \Phi(-0.71) = 1 - \Phi(0.71) = 1 - 0.7611 = 0.2389 \]

The 2025 HW1 key answered "0" to the matching question because no sampled age reached 80. The question asks for the normal-model probability: compute the z-score, use the table. That is what earns the marks.

Problem 4 · PCA by hand on four points (12 points)

The full PCA algorithm from Lecture 4 slide 20, start to finish. The TA's feedback on Quiz 2 was that students skipped checking whether the data was centred and lost the projection marks. Do the mean first, every time.

Four two-dimensional data points (rows are samples):

\[ (1, 1), \quad (3, 3), \quad (3, 5), \quad (5, 3) \]

Use \(\tfrac1n\) in the covariance matrix.

(a) Compute the mean vector and the centred data \(\mathbf Z\).
  1. \[ \boldsymbol\mu = \tfrac14\big((1,1) + (3,3) + (3,5) + (5,3)\big) = (3, 3) \]
  2. \[ \mathbf Z = \begin{bmatrix} -2 & -2 \\ 0 & 0 \\ 0 & 2 \\ 2 & 0 \end{bmatrix} \]

Each column of \(\mathbf Z\) sums to zero. If yours does not, the mean is wrong.

(b) Compute the covariance matrix \(\Sigma = \tfrac1n \mathbf Z^T \mathbf Z\).
  1. \[ \mathbf Z^T\mathbf Z = \begin{bmatrix} 4 + 0 + 0 + 4 & 4 + 0 + 0 + 0 \\ 4 & 4 + 0 + 4 + 0 \end{bmatrix} = \begin{bmatrix} 8 & 4 \\ 4 & 8 \end{bmatrix} \]
  2. \[ \Sigma = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix} \]
(c) Find the eigenvalues and unit eigenvectors of \(\Sigma\). Which one is the first principal component, and why?
  1. \[ \det(\Sigma - \lambda I) = (2 - \lambda)^2 - 1 = 0 \]
  2. \[ \lambda_1 = 3, \qquad \lambda_2 = 1 \]
  3. For \(\lambda_1 = 3\): \(-v_1 + v_2 = 0\): \[ \mathbf v_1 = \tfrac{1}{\sqrt 2}\begin{bmatrix} 1 \\ 1 \end{bmatrix} \]
  4. For \(\lambda_2 = 1\): \(v_1 + v_2 = 0\): \[ \mathbf v_2 = \tfrac{1}{\sqrt 2}\begin{bmatrix} 1 \\ -1 \end{bmatrix} \]
  5. \(\mathbf v_1\) is the first principal component: it has the largest eigenvalue, so the projected data has the largest variance along it. Fraction captured: \[ \frac{3}{3 + 1} = 75\% \]

Either sign of an eigenvector is accepted. Both quiz keys say so explicitly.

(d) Project the centred points onto \(\mathbf v_1\) to get the one-dimensional dataset \(y_i = \mathbf v_1^T \mathbf z_i\).
  1. \[ y_i = \frac{z_{i1} + z_{i2}}{\sqrt 2} \]
  2. \[ \mathbf y = \Big(\tfrac{-4}{\sqrt2},\ 0,\ \tfrac{2}{\sqrt2},\ \tfrac{2}{\sqrt2}\Big) = (-2.828,\ 0,\ 1.414,\ 1.414) \]

Project the centred rows. Projecting the raw points adds \(\mathbf v_1^T\boldsymbol\mu = 4.243\) to every score. The variance comes out the same, but the coordinates and the reconstruction in (f) do not.

(e) Compute the variance of the projected data and compare it with \(\lambda_1\).
  1. The scores have mean 0, so \[ \mathrm{Var}(y) = \tfrac14\big(8 + 0 + 2 + 2\big) = 3 = \lambda_1 \quad\checkmark \]
(f) Map each projected point back to \(\mathbb R^2\) and compute the reconstruction error (mean squared error). What does it equal?
  1. \[ \tilde{\mathbf x}_i = \boldsymbol\mu + y_i\,\mathbf v_1 \]
  2. \[ y_i \mathbf v_1 = \tfrac{z_{i1} + z_{i2}}{2}\,(1, 1): \quad (-2,-2),\ (0,0),\ (1,1),\ (1,1) \]
  3. \[ \tilde{\mathbf x} : \quad (1,1),\ (3,3),\ (4,4),\ (4,4) \]
  4. Errors \(\mathbf x_i - \tilde{\mathbf x}_i\): \[ (0,0),\ (0,0),\ (-1,1),\ (1,-1) \]
  5. \[ \mathrm{MSE} = \tfrac14\big(0 + 0 + 2 + 2\big) = 1 = \lambda_2 \]

Total variance is \(\lambda_1 + \lambda_2\). The first component keeps \(\lambda_1\), so what is lost per point is \(\lambda_2\). The formula sheet states this as \(\mathrm{SSE} = n\lambda_2\); here \(4 \times 1 = 4\), and \(\mathrm{MSE} = \mathrm{SSE}/n = 1\).

Problem 5 · A polynomial kernel on two points (10 points)

Quiz 2 Problem 2, with the inhomogeneous quadratic kernel instead of the linear one. The whole point of the kernel trick is that parts (c) to (e) never need \(\phi\) at all. Part (b) asks for it only so you can see the two routes agree.

Two points and a kernel:

\[ \mathbf x_1 = \begin{bmatrix} 2 \\ 0 \end{bmatrix}, \qquad \mathbf x_2 = \begin{bmatrix} 1 \\ 1 \end{bmatrix}, \qquad K(\mathbf x, \mathbf y) = (1 + \mathbf x^T\mathbf y)^2 \]
(a) Compute the kernel matrix \(\mathbf K\).
  1. \[ \mathbf x_1^T\mathbf x_1 = 4, \qquad \mathbf x_1^T\mathbf x_2 = 2, \qquad \mathbf x_2^T\mathbf x_2 = 2 \]
  2. \[ K_{11} = (1 + 4)^2 = 25, \qquad K_{12} = (1 + 2)^2 = 9, \qquad K_{22} = (1 + 2)^2 = 9 \]
  3. \[ \mathbf K = \begin{bmatrix} 25 & 9 \\ 9 & 9 \end{bmatrix} \]
(b) Write the feature map \(\phi\) for this kernel in \(\mathbb R^2\), compute \(\phi(\mathbf x_1)\) and \(\phi(\mathbf x_2)\), and verify \(\phi(\mathbf x_1)^T\phi(\mathbf x_2) = K_{12}\).
  1. Lecture 5 slide 10, quadratic kernel with \(m = 2\): \[ \phi(\mathbf x) = \big(1,\ \sqrt2 x_1,\ \sqrt2 x_2,\ x_1^2,\ x_2^2,\ \sqrt2 x_1 x_2\big)^T \]
  2. \[ \phi(\mathbf x_1) = (1,\ 2\sqrt2,\ 0,\ 4,\ 0,\ 0)^T \]
  3. \[ \phi(\mathbf x_2) = (1,\ \sqrt2,\ \sqrt2,\ 1,\ 1,\ \sqrt2)^T \]
  4. \[ \phi(\mathbf x_1)^T\phi(\mathbf x_2) = 1 + 4 + 0 + 4 + 0 + 0 = 9 = K_{12} \quad\checkmark \]
(c) Using only \(\mathbf K\), find \(\|\phi(\mathbf x_1)\|\), \(\|\phi(\mathbf x_2)\|\), the distance \(\|\phi(\mathbf x_1) - \phi(\mathbf x_2)\|\), and the cosine similarity in feature space.
  1. \[ \|\phi(\mathbf x_1)\| = \sqrt{K_{11}} = 5, \qquad \|\phi(\mathbf x_2)\| = \sqrt{K_{22}} = 3 \]
  2. \[ \|\phi(\mathbf x_1) - \phi(\mathbf x_2)\|^2 = K_{11} + K_{22} - 2K_{12} = 25 + 9 - 18 = 16 \]
  3. \[ \|\phi(\mathbf x_1) - \phi(\mathbf x_2)\| = 4 \]
  4. \[ \cos\theta_\phi = \frac{K_{12}}{\sqrt{K_{11}K_{22}}} = \frac{9}{15} = 0.6 \]
(d) Find \(\|\boldsymbol\mu_\phi\|\) and the centred kernel matrix \(\hat{\mathbf K}\).
  1. \[ \|\boldsymbol\mu_\phi\|^2 = \frac{1}{n^2}\sum_{i,j} K_{ij} = \frac{25 + 9 + 9 + 9}{4} = 13 \]
  2. \[ \|\boldsymbol\mu_\phi\| = \sqrt{13} \approx 3.606 \]
  3. Row means \(\bar r_1 = 17\), \(\bar r_2 = 9\); grand mean \(\bar g = 13\). Use \(\hat K_{ij} = K_{ij} - \bar r_i - \bar r_j + \bar g\): \[ \hat K_{11} = 25 - 17 - 17 + 13 = 4 \]
  4. \[ \hat K_{12} = 9 - 17 - 9 + 13 = -4 \]
  5. \[ \hat K_{22} = 9 - 9 - 9 + 13 = 4 \]
  6. \[ \hat{\mathbf K} = \begin{bmatrix} 4 & -4 \\ -4 & 4 \end{bmatrix} \]

Every row of a centred kernel matrix sums to zero. With two points the centred vectors are \(\pm\) each other, so \(\hat K_{12} = -\hat K_{11}\) is forced.

(e) Find the eigenvalues and unit eigenvectors of \(\hat{\mathbf K}\), the eigenvalues of the feature-space covariance \(\Sigma_\phi\), and the coordinate of each centred point along the first kernel principal component.
  1. \[ \det(\hat{\mathbf K} - \eta I) = (4 - \eta)^2 - 16 = \eta(\eta - 8) = 0 \]
  2. \[ \eta_1 = 8,\ \mathbf c_1 \propto \tfrac{1}{\sqrt2}(1, -1)^T; \qquad \eta_2 = 0,\ \mathbf c_2 = \tfrac{1}{\sqrt2}(1, 1)^T \]
  3. Eigenvalues of \(\Sigma_\phi\) are \(\eta/n\): \[ \lambda_1 = \tfrac82 = 4, \qquad \lambda_2 = 0 \]
  4. Coordinates \(a_i = \sqrt{\eta_1}\, v_1(i)\): \[ a_1 = \sqrt8 \cdot \tfrac{1}{\sqrt2} = 2, \qquad a_2 = -2 \]
  5. Check: \(\tfrac12(4 + 4) = 4 = \lambda_1\), and \(a_1^2 = 4 = \hat K_{11}\). All the variance sits on one direction.

Signs may be flipped. The quiz key accepted \(-\mathbf c_1\) with negated coordinates.

Part 3

Regression and concepts

Problem 6 · Least squares with one predictor (6 points)

The slope is a covariance over a variance and the line passes through the mean point. Residuals must sum to zero, which is your free check.

Five observations of a predictor \(x\) and a response \(y\):

\[ x = (1, 2, 3, 4, 5), \qquad y = (3, 4, 6, 7, 10) \]
(a) Fit \(\hat y = b + w x\) by least squares.
  1. \[ \mu_X = 3, \qquad \mu_Y = 6 \]
  2. Centred: \(x - \mu_X = (-2,-1,0,1,2)\), \(y - \mu_Y = (-3,-2,0,1,4)\).
  3. \[ w = \frac{\sum (x_i - \mu_X)(y_i - \mu_Y)}{\sum (x_i - \mu_X)^2} = \frac{6 + 2 + 0 + 1 + 8}{4 + 1 + 0 + 1 + 4} = \frac{17}{10} = 1.7 \]
  4. \[ b = \mu_Y - w\,\mu_X = 6 - 1.7(3) = 0.9 \]
  5. \[ \hat y = 0.9 + 1.7x \]
(b) Compute the fitted values and residuals, and verify \(\sum \epsilon_i = 0\) and \(\sum x_i \epsilon_i = 0\).
  1. \[ \hat{\mathbf y} = (2.6,\ 4.3,\ 6.0,\ 7.7,\ 9.4) \]
  2. \[ \boldsymbol\epsilon = \mathbf y - \hat{\mathbf y} = (0.4,\ -0.3,\ 0,\ -0.7,\ 0.6) \]
  3. \[ \sum\epsilon_i = 0.4 - 0.3 + 0 - 0.7 + 0.6 = 0 \quad\checkmark \]
  4. \[ \sum x_i\epsilon_i = 0.4 - 0.6 + 0 - 2.8 + 3.0 = 0 \quad\checkmark \]

They are the two derivative equations of the least-squares problem. Geometrically, the residual vector is perpendicular to both \(\mathbf 1\) and \(\mathbf x\), so \(\hat{\mathbf y}\) is the orthogonal projection of \(\mathbf y\) onto the plane they span.

(c) Compute the SSE and RMSE, then predict \(y\) at \(x = 6\). Add one sentence of caution about that prediction.
  1. \[ \mathrm{SSE} = 0.16 + 0.09 + 0 + 0.49 + 0.36 = 1.10 \]
  2. \[ \mathrm{RMSE} = \sqrt{\tfrac{1.10}{5}} = \sqrt{0.22} \approx 0.469 \]
  3. \[ \hat y(6) = 0.9 + 1.7(6) = 11.1 \]
  4. \(x = 6\) is outside the observed range 1 to 5, so this is extrapolation: the line has no data there to support it.

Problem 7 · Four one-line concept questions (4 points)

One point each. The TA's announcement said the exam tests understanding, not formula recall. Answer in one or two sentences.

(a) Why must the data be centred before computing \(\Sigma = \tfrac1n \mathbf Z^T\mathbf Z\) and projecting onto a principal component?

The covariance formula assumes deviations from the mean. With uncentred data, \(\tfrac1n \mathbf X^T\mathbf X\) mixes in the mean (\(\boldsymbol\mu\boldsymbol\mu^T\)) and is not the covariance, so the eigenvectors point in the wrong directions. Projection scores must also be computed from \(\mathbf x_i - \boldsymbol\mu\), otherwise every score is shifted by \(\mathbf v^T\boldsymbol\mu\) and reconstructions are wrong.

(b) Two random variables have correlation 0. Are they independent? Explain.

Not necessarily. Independence implies zero correlation, but zero correlation only says there is no linear relationship. A nonlinear dependence (for example \(Y = X^2\) with \(X\) symmetric about 0) gives correlation 0 while \(Y\) is fully determined by \(X\). The converse holds only for jointly normal variables.

(c) The sample \(\{1.5, 2, 3.5, 2, 5, 4, 3\}\) has mean 3 and median 3. One value is mistyped as 32 instead of 3.5. What happens to each measure, and which is more robust?

The mean jumps to \(49/7 = 7\) because every value enters the sum; the median stays at 3 because only the ordering matters and one extreme value does not change which point sits in the middle. The median is the robust measure of central tendency (Lecture 2 slide 15).

(d) Why does kernel PCA solve an \(n \times n\) eigenproblem instead of diagonalising the feature-space covariance \(\Sigma_\phi\)?

\(\Sigma_\phi\) has the size of the feature space, which is huge for polynomial kernels and infinite for the Gaussian kernel, and \(\phi\) is never computed. Every principal direction is a weighted sum of the mapped points, so the problem is rewritten in the \(n\) weights: \(\hat{\mathbf K}\mathbf c = \eta\mathbf c\), with variance \(\eta/n\). Only kernel values appear.

After the mock: where to review

If you lost marks on…Reread
P1 projection or distancesData, vectors and distributions, the projection and distance cards
P2 cdf, median, finding \(c\)Data, vectors and distributions, pmf / cdf / pdf cards and HW1 Q4–5
P3 covariance matrix, correlation, normalFrom covariance to PCA, Parts 1–2
P4 eigenvectors, projection, MSEFrom covariance to PCA, Parts 3–5 and HW2 Q1–2
P5 kernel matrix, centring, kernel PCAFrom kernels to kernel PCA, Parts 2–4
P6 slope, residuals, RMSELinear regression, Parts 1–2

Next: Mock midterm 2 changes the emphasis to quiz-style projection with a given eigenvector, kernel operations on three points, and multiple regression.