4 pts \(\displaystyle R(w) = \frac{1}{5} \sum_{i=1}^5 (y_i - w)^2\)
Solution
The minimizer of mean squared error for a constant model is the mean, as discussed in Chapter 1.2. So,
This page is meant to give you quick access to problems and their solutions. Refer to the original exam PDF, linked above, for test-taking instructions and formatting. Note that we’ve kept the problem text identical, which is why you may see things like “write your answer in the box below” despite there not being a box on this page.
Suppose we’d like to find the optimal constant parameter, \(w^{\ast}\), for the constant model \(h(x_i)=w\), using the following dataset of \(n=5\) values:
In each part, find the value of \(w^{\ast}\) that minimizes the given \(R(w)\). Show your work in the space provided, and write your final answer in the bottom-right corner of the box. Your answers should be numbers with no variables. Note: There is no need to use calculus here.
4 pts \(\displaystyle R(w) = \frac{1}{5} \sum_{i=1}^5 (y_i - w)^2\)
The minimizer of mean squared error for a constant model is the mean, as discussed in Chapter 1.2. So,
4 pts \(\displaystyle R(w) = \frac{1}{5} \sum_{i=1}^5 (\sqrt{y_i} - w)^2\)
This is asking for the best constant prediction for the transformed values \(\sqrt{y_i}\). The transformed data are
so
4 pts \(\displaystyle R(w) = \frac{1}{5} \sum_{i=1}^5 (y_i - \sqrt{w})^2\)
Let \(u=\sqrt{w}\). The loss becomes
which is minimized at the mean of the original \(y_i\) values:
Since \(u=\sqrt{w}\), we have
2 pts Which answer from above is also the minimizer of \(\displaystyle R(w) = \sqrt{\frac{1}{5} \sum_{i=1}^5 (y_i - w)^2}\)?
The square root function is strictly increasing, so minimizing
is equivalent to minimizing
That is exactly the objective from part a), so the answer is the answer from part a).
Suppose we fit a simple linear regression model to a dataset of \(n\) points, \((x_1,y_1),(x_2,y_2),\ldots,(x_n,y_n)\), by minimizing mean squared error. Let \(\bar x\) and \(\bar y\) be the means of the \(x\)-values and \(y\)-values, respectively, and suppose the standard deviations \(\sigma_x\) and \(\sigma_y\) are both positive. Let
be the best simple linear regression line for the original dataset.
Now, we create a new dataset of \(n+1\) points by starting with the original dataset and adding one new point,
where \(c\) is a constant. Let
be the best simple linear regression line for the new dataset.
6 pts Prove that \(w_1’ = w_1^{\ast}\), i.e. that the new slope is the same as the old slope, no matter what \(c\) is. Hint: Start with any of the formulas for the optimal slope that involve summations in the numerator and denominator, and separate the sums.
The optimal slope for simple linear regression can be written as
as derived in Chapter 2.3. There are several other equivalent formulas, e.g. with \(\sum_{i=1}^n (x_i-\bar{x})(y_i-\bar{y})\) on the numerator, but this one keeps the algebra simplest, as it doesn’t require us to think about the new value of \(\bar y\).
For the new dataset, the mean of the \(x\)-values is still \(\bar{x}\), since
The denominator of the new slope is therefore
The numerator of the new slope is
So the numerator and denominator in this formula are both unchanged, meaning \(w_1’=w_1^{\ast}\).
3 pts Which of the following expressions is equal to \(w_0’ - w_0^{\ast}\), the difference between the new intercept and the old intercept?
The intercept of the optimal simple linear regression line is
The new \(x\)-mean is still \(\bar{x}\), and part a) showed that the new slope is still \(w_1^{\ast}\). The new \(y\)-mean is
So,
Let \(\vec x = \begin{bmatrix} 2 \\ 1 \\ 1 \end{bmatrix}\) and \(\vec z = \begin{bmatrix} 3 \\ 9 \\ 3 \end{bmatrix}\), and suppose \(\vec y \in \mathbb{R}^3\) is such that
the projection of \(\vec x\) onto \(\vec y\) is \(\vec 0\) and that \(\vec y \cdot \vec y = \vec y \cdot \vec z = 45\).
4 pts Find the projection of \(\vec z\) onto \(\vec x\). Show your work, and write your final answer in the box provided. Give your answer as a vector with no variables.
Using the projection formula from Chapter 3.4,
Here,
so
6 pts Write \(\vec z\) as a linear combination of \(\vec x\) and \(\vec y\). Show your work, and fill in each box with a number with no variables. Hint: What is the relationship between \(\vec x\) and \(\vec y\)?
Since the projection of \(\vec{x}\) onto \(\vec{y}\) is \(\vec{0}\) and \(\vec{y}\cdot\vec{y}=45\), \(\vec{y}\) is nonzero and \(\vec{x}\cdot\vec{y}=0\). In other words, \(\vec{x}\) and \(\vec{y}\) are orthogonal.
Suppose
Taking dot products with \(\vec{x}\) gives
Using the work from part a), \(\vec{z}\cdot\vec{x}=18\) and \(\vec{x}\cdot\vec{x}=6\). Since \(\vec{y}\cdot\vec{x}=0\),
so \(a=3\).
Now take dot products with \(\vec{y}\):
The problem tells us that \(\vec{z}\cdot\vec{y}=\vec{y}\cdot\vec{y}=45\), and \(\vec{x}\cdot\vec{y}=0\), so
and therefore \(b=1\). So,
Suppose \(S = \left\lbrace \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{bmatrix} : x_1 + x_2 + 2x_3 = 0 \text{ and } x_3 = x_4 \right\rbrace\). State one basis for \(S\). Your answer should be a list of vectors with no variables.
\(\text{one basis for } S =\) ______
The condition \(x_3=x_4\) means we can write \(x_3=x_4=b\). The other condition gives
so \(x_1=-x_2-2b\). Let \(x_2=a\). Then every vector in \(S\) can be written as
So, one basis for \(S\) is
Another way to think about this: since \(\dim(S)=2\) (the subspace has two “degrees of freedom”, or free variables), any two linearly independent vectors in \(S\) span all of \(S\) (see Chapter 4.3). So, we could just play with the numbers until we end up with two vectors that are not scalar multiples of each other that both satisfy the conditions of inclusion in \(S\). For instance,
is also a valid basis.
Suppose \(A\) is a \(7 \times 12\) matrix. Fill in each blank with an integer with no variables.
(2 pts) What is the minimum possible value of \(\text{dim}(\text{nullsp}(A))\)? ______
(2 pts) What is the maximum possible value of \(\text{dim}(\text{nullsp}(A))\)? ______
By the rank-nullity theorem from Chapter 5.4,
The rank of a \(7\times 12\) matrix is at least \(0\) and at most \(7\). So the dimension of the null space is
This is as small as possible when \(\text{rank}(A)=7\), giving minimum \(\text{dim}(\text{nullsp}(A)) = 5\), and as large as possible when \(\text{rank}(A)=0\), giving maximum \(\text{dim}(\text{nullsp}(A)) = 12\).
Find the area enclosed by the polygon with vertices \((0, 0)\), \((4, 6)\), \((1, 8)\), and \((-3, 2)\). Show your work, and write your answer in the box provided.
Let
Then
so the four vertices are the coordinates of \(\vec{0}\), \(\vec{u}\), \(\vec{u}+\vec{v}\), and \(\vec{v}\). This means the polygon is a parallelogram. The area of the parallelogram is the absolute value of the determinant of the matrix whose columns are the two side vectors, as in Chapter 6.1. We picked \(\vec{u}\) and \(\vec{v}\) because they are the side vectors from the origin, but using any two of the three nonzero vertices as the columns would give the same answer after taking the absolute value: adding one column to another does not change the determinant.

So,
Suppose \(X\) is an \(n \times d\) matrix with linearly independent columns, \(d<n\), and \(\vec y \in \mathbb{R}^n\).
Furthermore, suppose \(P\) is the matrix that projects vectors in \(\mathbb{R}^n\) onto \(\text{colsp}(X)\), and \(\vec p = P \vec y\) is the projection of \(\vec y\) onto \(\text{colsp}(X)\).
Finally, let \(Q\) be an \(n \times n\) orthogonal matrix.
4 pts
(2 pts) What is \(\text{det}(P)\)?
(2 pts) What is \(\text{det}(Q)\)?
Since \(P\) projects onto \(\text{colsp}(X)\) and \(d<n\), multiple vectors in \(\mathbb{R}^n\) will have the same projection onto \(\text{colsp}(X)\). So \(P\) is not invertible, and therefore \(\det(P)=0\).
Since \(Q\) is orthogonal, \(Q^TQ=I\). Taking determinants gives
so, since \(\det(I)=1\), \(\text{det}(Q^T) = \det(Q)\), and in general \(\text{det}(AB) = \det(A)\det(B)\) for square \(A\) and \(B\), we have
and therefore \(\det(Q)\) is either \(-1\) or \(1\).
2 pts Which of the following vectors is orthogonal to \(\text{colsp}(X)\)?
The vector \(P\vec{y}\) is the projection of \(\vec{y}\) onto \(\text{colsp}(X)\), so the error vector
is orthogonal to \(\text{colsp}(X)\). This is the same projection geometry used in Chapter 6.3; the novel thing here was the representation of the error vector as a linear combination of the columns of \(I-P\).
6 pts Prove that the projection of \(Q \vec y\) onto \(\text{colsp}(QX)\) is \(Q \vec p\). Hint: Start by showing that the matrix that projects vectors in \(\mathbb{R}^n\) onto \(\text{colsp}(QX)\) is \(Q P Q^T\).
Since \(X\) has linearly independent columns, the matrix that projects onto \(\text{colsp}(X)\) is
Now, the matrix that projects onto \(\text{colsp}(QX)\) is
using the fact that \(Q^TQ=I\). Therefore, the projection of \(Q\vec{y}\) onto \(\text{colsp}(QX)\) is
Why does this happen? Think of \(Q\) as a rotation matrix. This is saying that if we:
Rotate \(\vec y\) and rotate \(\text{colsp}(X)\), and project the rotated \(\vec y\) onto the rotated \(\text{colsp}(X)\), OR
Project the original \(\vec y\) onto the original \(\text{colsp}(X)\), and then rotate the projected vector,
we end up with the same vector in either case.
Suppose we’d like to fit a multiple linear regression model to predict \(\texttt{cost}_i\), the cost in dollars of parking in an Ann Arbor parking garage, using \(\texttt{hours}_i\), the number of hours parked.
For each row \(i\), the corresponding augmented feature vector is \(\text{Aug}(\vec x_i) = \begin{bmatrix} 1 & \texttt{hours}_i & \max(0,\texttt{hours}_i-2) \end{bmatrix}^T\) so the model is of the form
The model is fit by minimizing mean squared error.
4 pts Suppose the dataset has four rows, and the number of hours parked in those rows is
\(3\), \(0\), \(5\), and \(1\), respectively. Write the first four rows of the design matrix \(X\). Your answer should be a matrix with four rows and no variables.
\(X =\) ______
Each row is the transpose of the augmented feature vector
For \(\texttt{hours}_i=3,0,5,1\), the values of \(\max(0,\texttt{hours}_i-2)\) are \(1,0,3,0\), respectively. So,
2 pts Give a one-sentence English explanation of the meaning of \(w_2\).
The coefficient \(w_2\) is the change in the hourly slope after 2 hours; after the first 2 hours, each additional hour changes the predicted cost by \(w_1+w_2\) dollars instead of \(w_1\) dollars.
6 pts Once again, suppose the dataset has four rows. In each of the following subparts, we provide the number of hours parked in the dataset. Find the rank of the design matrix \(X\) in each case. Fill in each blank with an integer with no variables.
(2 pts) \(3\), \(0\), \(5\), and \(1\) \(\text{rank}(X) = \_\_\_\_\_\_\)
(2 pts) \(2\), \(0\), \(2\), and \(1\) \(\text{rank}(X) = \_\_\_\_\_\_\)
(2 pts) \(3\), \(4\), \(5\), and \(6\) \(\text{rank}(X) = \_\_\_\_\_\_\)
This feature engineering setup is an example of the multiple linear regression design matrices from Chapter 7.2.
The design matrix is
The three columns are linearly independent, so \(\text{rank}(X)=3\).
The design matrix is
The third column is all zero, while the first two columns are linearly independent. So \(\text{rank}(X)=2\).
If all hour values are greater than \(2\), then
This means column 2 is equal to \(2\) times column 1 plus column 3:
So the rank is at most \(2\). Since the hour values are not all the same, columns 1 and 3 are linearly independent, and \(\text{rank}(X)=2\).
Let \(\vec a \in \mathbb{R}^2\) and let
for all vectors \(\vec x\) such that \(\vec a \cdot \vec x > 0\); if \(\vec a \cdot \vec x \leq 0\), then \(f(\vec x)\) is undefined. Suppose that
3 pts Which of the following could be \(\vec a\)? Select all that apply.
\(\begin{bmatrix}2\\6\end{bmatrix}\)
Let
Then \(f(\vec{x})=h(g(\vec{x}))\). Using the chain rule from Chapter 8.2,
Now,
so
At \(\vec{x}=\begin{bmatrix}2\\1\end{bmatrix}\), this becomes
Since \(f\) is defined at \(\begin{bmatrix}2\\1\end{bmatrix}\), this must mean that \(\vec a \cdot \vec x\), which is equal to \(2a_1 + a_2\), is positive. Multiplying both sides by this positive denominator gives
This says \(\vec{a}\) must be a positive scalar multiple of \(\begin{bmatrix}1\\3\end{bmatrix}\). Among the answer choices, the vectors with that form are \(\begin{bmatrix}1\\3\end{bmatrix}\) and \(\begin{bmatrix}2\\6\end{bmatrix}\).
Another way to approach this would be to take the equation
from above, and realize the expression on the right is also equal to \(\frac{1}{2a_1+a_2} \begin{bmatrix}a_1\\a_2\end{bmatrix}\), which allows us to set up a system of equations directly for \(a_1\) and \(a_2\):
Both equations say the same thing: \(a_2 = 3a_1\), i.e. that \(a_2\) must be triple \(a_1\), so \(\vec a\) is a scalar multiple of \(\begin{bmatrix}1\\3\end{bmatrix}\). But, don’t forget the added constraint that \(2a_1 + a_2\) must be positive.
4 pts Suppose we use gradient descent to minimize \(f(\vec x)\) using an initial guess of \(\vec x^{(0)} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}\) and a learning rate of \(\alpha = 1/2\). Find \(\vec x^{(1)}\). Show your work, and write your answer in the box provided. Your answer should be a vector with no variables.
The gradient descent update from Chapter 8.3 is
Here, \(\vec{x}^{(0)}=\begin{bmatrix}2\\1\end{bmatrix}\), \(\alpha=1/2\), and \(\nabla f(\vec{x}^{(0)})=\begin{bmatrix}1/5\\3/5\end{bmatrix}\). So,
2 pts This part is unrelated to the previous parts.
Suppose \(g: \mathbb{R} \to \mathbb{R}\). True or false: if \(g\) has a global minimum and no local maxima, it must be convex.
This is false. For instance, consider
This function has a global minimum, since \(g(x)\to\infty\) as \(x\to\infty\) and as \(x\to-\infty\). Also,
The derivative only changes sign at \(x=-3/4\), where it changes from negative to positive, so \(g\) has a local minimum and no local maxima. But,
which is negative for some \(x\) values, for instance \(x=-1/4\). So \(g\) is not convex. See Chapter 8.5 for the convexity condition.

Let \(A=\begin{bmatrix}2&4\\4&2\end{bmatrix}\).
8 pts Find all eigenvalues and eigenvectors of \(A\). Show your work, and organize your answers as follows:
Put the larger eigenvalue in \(\lambda_1\), and a corresponding eigenvector in \(\vec v_1\).
Put the smaller eigenvalue in \(\lambda_2\), and a corresponding eigenvector in \(\vec v_2\).
The characteristic polynomial is
So the eigenvalues are \(6\) and \(-2\). Alternatively, using the trace and determinant facts from Chapter 9.1, you can arrive at this quickly by seeing that the eigenvalues must add to \(\text{trace}(A) = 2 + 2 = 4\) and multiply to \(\det(A) = 2 \cdot 2 - 4 \cdot 4 = -12\).
For \(\lambda=6\), write an eigenvector as
Then
so
Both equations say \(a=b\), so one corresponding eigenvector is \(\begin{bmatrix}1\\1\end{bmatrix}\).
For \(\lambda=-2\), we similarly solve
so
Both equations say \(a=-b\), so one corresponding eigenvector is \(\begin{bmatrix}1\\-1\end{bmatrix}\). Therefore,
4 pts True or false: for all integer values of \(k\), the matrix \(B=\begin{bmatrix}2&4&0\\4&2&0\\0&0&k\end{bmatrix}\) is diagonalizable.
This is true. Since \(B\) is block diagonal (see Chapter 9.4), we can read off eigenvalues and eigenvectors from its individual blocks.
The top-left block has two linearly independent eigenvectors, \(\begin{bmatrix}1\\1\\0\end{bmatrix}\) and \(\begin{bmatrix}1\\-1\\0\end{bmatrix}\), with eigenvalues \(6\) and \(-2\), and \(\begin{bmatrix}0\\0\\1\end{bmatrix}\) is an eigenvector with eigenvalue \(k\). These three eigenvectors are linearly independent no matter what \(k\) is. Therefore \(B\) is diagonalizable for all integer values of \(k\).
Another way to think about this is that for any \(k\), the matrix \(B\) is symmetric, and hence diagonalizable, as told to us by the spectral theorem.
The state diagram below describes a Markov chain with three states. \(a\) and \(b\) are both constants between 0 and 1.
Suppose that in the long run, \(\displaystyle\frac{25}{60}\) of the time is spent in state 1, \(\displaystyle\frac{21}{60}\) of the time is spent in state 2, and \(\displaystyle\frac{14}{60}\) of the time is spent in state 3.
Find the values of \(a\) and \(b\). Show your work, and write your final answers in the boxes provided. Your answers should be numbers with no variables.
As discussed in Chapter 9.3, a steady-state distribution is an eigenvector of the adjacency matrix with eigenvalue \(1\), with the additional constraint that its entries sum to \(1\). We are given that the steady-state distribution is
which already sums to \(1\). The adjacency matrix for this Markov chain is
So we need to choose \(a\) and \(b\) so that \(A\vec x=1\vec x=\vec x\). This gives
or equivalently,
The second equation gives
The third equation gives
These values also satisfy the first equation, since
Suppose \(A\) is a \(3 \times 3\) symmetric matrix with rank \(2\). The eigenspace corresponding to \(\lambda=9\) is the plane
Suppose \(A=Q\Lambda Q^T\), where \(Q\) is an orthogonal matrix and \(\Lambda\) is a diagonal matrix with eigenvalues of \(A\) on the diagonal, sorted from largest to smallest.
3 pts Find \(\Lambda\). Your answer should be a matrix with no variables.
Since \(A\) is symmetric, the spectral theorem from Chapter 9.5 tells us that \(A\) is diagonalizable with orthogonal eigenspaces. The eigenspace for \(\lambda=9\) is a plane, so it is 2-dimensional. Since \(A\) has rank \(2\), it is not invertible, so it has at least one eigenvalue of \(0\). In fact, it has exactly one eigenvalue of \(0\), since the other two eigenvalues are both \(9\).
Since the eigenvalues are sorted from largest to smallest,
8 pts Consider the vector
Find \(A\vec v\). Show your work, and write your final answer in the box provided. Your answer should be a vector with no variables. Hint: What does the spectral theorem tell us?
The vector \(\begin{bmatrix}1\\2\\0\end{bmatrix}\) is in the eigenspace for \(\lambda=9\), since it satisfies the equation of the eigenspace, \(2x-y+2z=0\):
This means \(\begin{bmatrix}1\\2\\0\end{bmatrix}\) is an eigenvector of \(A\) with eigenvalue \(9\).
The vector \(\begin{bmatrix}2\\-1\\2\end{bmatrix}\) is orthogonal to the plane \(2x-y+2z=0\) (conveniently, \(\begin{bmatrix} 2 \\ -1 \\ 2 \end{bmatrix}\) contains the coefficients of the plane equation, and the coefficients of the plane equation define a vector orthogonal to the plane). The spectral theorem tells us that this vector is in the eigenspace corresponding to \(\lambda=0\), because eigenvectors for different eigenvalues are orthogonal for symmetric matrices. Therefore,
Let \(\tilde X\) be a \(4 \times 2\) centered matrix (i.e. in which each column has a mean of 0) with columns \(\vec a\) and \(\vec b\):
Suppose \(\tilde X = U \Sigma V^T\) is the singular value decomposition of \(\tilde X\), \(\vec v_1 = \begin{bmatrix}3/5\\4/5\end{bmatrix}\) is the first column of \(V\), and \(\sigma_1 = 10\) is the largest singular value.
3 pts How many possible vectors are there for \(\vec v_2\), the second column of \(V\)?
Since \(V\) is an orthogonal matrix, its columns must be unit vectors that are orthogonal to each other. In \(\mathbb{R}^2\), there are exactly two unit vectors orthogonal to \(\begin{bmatrix}3/5\\4/5\end{bmatrix}\), namely \(\begin{bmatrix}-4/5\\3/5\end{bmatrix}\) and \(\begin{bmatrix}4/5\\-3/5\end{bmatrix}\). So there are two possible vectors for \(\vec{v}_2\).
5 pts Write \(\vec u_1\), the first column of \(U\), as a linear combination of the columns of \(\tilde X\). Show your work, and fill in each box with a number with no variables.
Recall that the key relationship linking the first column of \(U\) and the first column of \(V\) in \(\tilde X = U \Sigma V^T\) is
This means
Since the columns of \(\tilde{X}\) are \(\vec{a}\) and \(\vec{b}\),
and since \(\sigma_1=10\),
4 pts Given the information above, what is the maximum possible variance of principal component \(2\)? Give your answer as a number with no variables.
maximum possible variance of principal component \(2\) = ______
Chapter 10.4 tells us that the variance of principal component \(j\) is
We also know that the singular values are sorted from largest to smallest, so \(\sigma_1 \geq \sigma_2\). So, the variance of principal component \(2\), \(\frac{\sigma_2^2}{n}\), is at most equal to the variance of principal component \(1\), \(\frac{\sigma_1^2}{n}\).
Therefore, the maximum possible variance of principal component \(2\) is the variance of principal component \(1\):
What is one topic you studied a lot for that was not on the Final Exam? Blank answers will receive no credit!