How many rows and columns does \(X\) have? What is \(\text{rank}(X)\)?
Solution
\(X\) is a \(2 \times 3\) matrix, matching the dimensions of \(\Sigma\). \(\text{rank}(X)\) is 2, since there are 2 non-zero singular values.
due for completion at 11:59PM Ann Arbor Time on Monday, June 22nd, 2026
Each lab worksheet will contain several activities, some of which will involve writing code and others that will involve writing math on paper. To receive credit for a lab, you must complete as many of the activities as you can in 2 hours and submit a PDF of your work to Gradescope. We will provide specific instructions on how to submit programming activities (e.g. submitting the notebook or including a screenshot of some output).
Feel free to work with others in the course, but you must submit individually.
Suppose \(X\) is any \(n \times d\) matrix. Then, there exists a singular value decomposition (SVD) of \(X\) of the form
where:
| Matrix | Shape | Values Come From | Properties |
|---|---|---|---|
| \(U\) | \(n \times n\) | Columns are eigenvectors of \(XX^T\), called the left singular vectors of \(X\) | Orthogonal, \(U^TU = UU^T = I_{n \times n}\) |
| \(\Sigma\) | \(n \times d\) | Each singular value \(\sigma_i\) is the square root of the \(i\)-th largest eigenvalue of \(X^TX\) (or \(XX^T\)) | Diagonal, with value in position \((i, i)\) equal to \(\sigma_i\) for \(i=1,2,\dots,r = \text{rank}(X)\) |
| \(V\) | \(d \times d\) | Columns are eigenvectors of \(X^TX\), called the right singular vectors of \(X\) | Orthogonal, \(V^TV = VV^T = I_{d \times d}\) |
If \(\vec u_i\) and \(\vec v_i\) are the \(i\)-th left and right singular vectors of \(X\), respectively, then \(X\vec v_i = \sigma_i \vec u_i\).
Suppose the matrix \(X\) has the singular value decomposition \(X=U\Sigma V^T\) where
How many rows and columns does \(X\) have? What is \(\text{rank}(X)\)?
\(X\) is a \(2 \times 3\) matrix, matching the dimensions of \(\Sigma\). \(\text{rank}(X)\) is 2, since there are 2 non-zero singular values.
Find \(\vec v_2\).
\(\vec v_2\) is the eigenvector of \(X^TX\) corresponding to the eigenvalue 2. It’s also a unit vector, meaning we need to find a unit vector that’s orthogonal to the other two columns, so \(\vec v_2 = \begin{bmatrix}\sqrt{2} / 2 \\ 0 \\ -\sqrt{2} / 2 \end{bmatrix}\)
Given that the first column of \(X\) and third column of \(X\) sum to \(\begin{bmatrix}0 \\ 5\end{bmatrix}\), find \(\sigma_1\).
The left side of the equation is the sum of \(X\)’s first and third columns, scaled by \(1 / \sqrt{2}\), so we can use the fact given in the problem here:
Consider the rank-\(2\) matrix \(X=\begin{bmatrix}1 & 2 & 2 \\ 1 & 3 & 3\end{bmatrix}\).
Write \(X\) as a sum of two rank-1 outer products, e.g. \(X=\vec x_1 \vec y_1^T + \vec x_2 \vec y_2^T\).
\(X\) has a unique first column, while the second and third columns are the same. So, we can use a similar idea to the CR decomposition:
Find \(XX^T\) and \(X^TX\), and the trace and determinant of each. Feel free to use numpy.
If \(X\) is any \(n \times d\) matrix, which of the following are guaranteed to be true, and why? Hint: How does the trace of a matrix relate to its eigenvalues? How are the eigenvalues of \(XX^T\) and \(X^TX\) related?
\(XX^T\) and \(X^TX\) share the same non-zero values. Since the trace is equivalent to the sum of the eigenvalues, the non-zero eigenvalues being the same results in the same sum, as the zero eigenvalues don’t affect it.
However, the same is not true for the determinant. In the case where \(n \neq d\), one of \(XX^T\) or \(X^TX\) will be larger. The larger matrix must have a zero eigenvalue because \(\text{rank}(XX^T) = \text{rank}(X^TX)\), so its determinant will be 0. We can’t guarantee that \(X^TX\) won’t be full rank, so its possible for the determinant to not be 0.
Suppose \(X\) is a \(5 \times 2\) matrix with singular value decomposition \(X=U \Sigma V^T\), and that \(\vec v_1\) and \(\vec v_2\) are the first and second columns of \(V\), respectively. Furthermore, suppose \(\vec w \in \mathbb{R}^2\) is a vector such that
Find \(V^T\vec w\).
We can simplify this further thanks to \(V\) being an orthogonal matrix. \(\vec v_1\) and \(\vec v_2\) are orthogonal, and their norms are both 1.
Suppose \(X\)’s two singular values are \(\sigma_1 = 10\) and \(\sigma_2 = 3\). Find \(\Sigma V^T\vec w\).
Let \(\vec z = \Sigma V^T\vec w\). In English, what does \(\vec z\) represent, relative to \(\vec w\)?
\(V^T\vec w\) rotates \(\vec w\) using the right singular vectors as the basis. Since \(\vec w\) is already composed of those vectors, it returns the coefficients back in a vector. \(\Sigma\) then shifts the resulting vector by scaling each component using the singular values.
The goal of principal component analysis (PCA) is reducing the dimensionality of a dataset by constructing new features — called principal components.
These new features are linear combinations of the existing features in the data, and are constructed to minimize the mean squared orthogonal error of the data when projected onto the new features.
As we see in Chapter 10.3, this is equivalent to finding the directions along which the data is most spread out.

The plot on the left shows the direction vectors \(\vec v_1\) and \(\vec v_2\) which define the first and second principal components, respectively. \(\vec v_1\) is the direction that captures the most variability, followed by \(\vec v_2\). Note that \(\vec v_1\) and \(\vec v_2\) are orthogonal, which results in the principal components (new features) being uncorrelated, as we see in the plot on the right.
The “PCA recipe” is as follows:
Starting with an \(n \times d\) matrix \(X\) of \(n\) data points in \(d\) dimensions and mean-center the data by subtracting the mean of each column from itself. The new matrix is \(\tilde X\).
Compute the singular value decomposition of \(\tilde X\): \(\tilde X = U \Sigma V^T\).
The columns of \(V\) (rows of \(V^T\)) describe the directions of maximal variance in the data! For instance, the single “best direction” is the eigenvector of \(\tilde X \tilde X^T\) with the largest eigenvalue, i.e. \(\vec v_1\) in \(\tilde X = U \Sigma V^T\).
Principal component (new feature) \(j\) comes from multiplying \(\tilde X\) by the \(j\)-th column of \(V\).
The proportion of total variance in \(\tilde X\) that is explained by \(\text{PC}_j\) is
Suppose \(A\), \(B\), and \(C\) are each \(100 \times 2\) matrices, representing \(n=100\) points in \(\mathbb{R}^2\). The three datasets are shown in the scatter plots below. (Matrix \(A\) is in Plot A, matrix \(B\) is in Plot B, and matrix \(C\) is in Plot C.)

Assume that \(A\), \(B\), and \(C\) are each already mean-centered.
If we applied PCA to each of the above datasets, and created just one principal component in each case, for which dataset would the first principal component have the smallest mean squared orthogonal error — \(A\), \(B\), or \(C\)?
\(B\) has a strong negative correlation, with little spread in the perpendicular direction, while \(A\) and \(C\)’s dominant directions aren’t as clear.
Suppose \(\tilde{X}=U \Sigma V^T\) is the singular value decomposition of \(\tilde{X}\), and that
Which dataset is most likely to be \(\tilde{X}\) — \(A\), \(B\), or \(C\)?
The singular values tell us that one direction is being scaled by 16, while the other is scaled by 4, meaning most of the variance is captured in the \(\vec v_1\) direction. \(\vec v_1\) has a positive \(x\) component and a negative \(y\) component, which matches the slope of plot \(B\)’s dominant direction, since \(A\) and \(B\)’s dominant directions are more positive.
Again, suppose \(\tilde{X}=U \Sigma V^T\) is the singular value decomposition of \(\tilde{X}\), and that
What is the proportion of the total variance in \(\tilde{X}\) that is accounted for by the first principal component?
Suppose that in the graph of principal component 2 vs. principal component 1 (i.e. with PC 1 on the \(x\)-axis and PC 2 on the \(y\)-axis), a particular data point is plotted at \((4, 2)\). What is the corresponding point in the original (mean-centered) dataset? Your answer should be a tuple of two numbers, \((x, y)\) (or equivalently, a vector in \(\mathbb{R}^2\)). Hint: Start by understanding the plot on Page 4.
There are two ways to approach this problem:
Option 1: Dot Products and Transformation
In the PC2 vs PC1 plot in the recap, you may have noticed the coordinates of \(\vec x_{12}\) were \((\vec x_{12} \cdot \vec v_1, \vec x_{12} \cdot \vec v_2)\). This comes from multiplying \(V^T\vec x_{12}\):
If this looks familiar, that’s because it’s similar to 3c! In 3c, \(V^T\vec w\) rotated \(\vec w\) by translating it into a space with {\(\vec v_1,\vec v_2\)} as its basis. So, if we know a point’s coordinates in \(\vec v_1, \vec v_2\) space, we can work backwards to solve for the point’s coordinates in \(x,y\) space:
Now we have a system of equations to solve for the coordinate of \(\vec w\):
Option 2: Thinking in Terms of Linear Combinations
\((4, 2)\) are coefficients in the basis \(\lbrace \vec v_1, \vec v_2\rbrace\). Since we know \(\vec v_1\) and \(\vec v_2\)’s directions in \(x,y\) space, getting the point’s coordinates in \(x,y\) space just involves computing the linear combination, using the coordinates in \(\vec v_1, \vec v_2\) space as coefficients: