











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












First name
Last name
Fill in the bubbles for ALL correct choices: there may be more than one correct choice, but there is always at least one correct choice. NO partial credit: the set of all correct answers must be checked.
(1) [4 pts] Which of the following are true for the k-nearest neighbor (k-NN) algorithm?
A: k-NN can be used for both classification and regression.
B: As k increases, the bias usually increases.
© C: The decision boundary looks smoother with smaller values of k.
© D: As k increases, the variance usually increases.
(2) [4 pts] Let X be a matrix with singular value decomposition X = UΣV>. Which of the following are true for all X?
A: rank(X) = rank(Σ).
© B: If all the singular values are unique, then the SVD is unique.
C: The first column of V is an eigenvector of X>^ X.
D: The singular values and the eigenvalues of X>^ X are the same.
A is correct because the number of non-zero singular values is equal to the rank. B is incorrect because you could change both U → −U, V → −V. C is correct because the SVD and eigendecomposition of X>^ X is VΣ^2 V>. D is correct as X>^ X is positive semidefinite, so the eigenvalues can’t be negative.
(3) [4 pts] Lasso (with a fictitious dimension), random forests, and principal component analysis (PCA) all...
A: can be used for dimensionality reduction or feature subset selection
© B: compute linear transformations of the input features
© C: are supervised learning techniques
D: are translation invariant: changing the origin of the coordinate system (i.e., translating all the training and test data together) does not change the predictions or the principal component directions
Option B is incorrect because random forests don’t compute linear transformations. Option C is incorrect because PCA is unsupervised.
(4) [4 pts] Suppose your training set for two-class classification in one dimension (d = 1; xi ∈ R) contains three sample points: point x 1 = 3 with label y 1 = 1, point x 2 = 1 with label y 2 = 1, and point x 3 = −1 with label y 3 = −1. What are the values of w and b given by a hard-margin SVM?
© A: w = 1, b = 1
© B: w = 0, b = 1
C: w = 1, b = 0
© D: w = ∞, b = 0
(5) [4 pts] Use the same training set as part (d). What is the value of w and b given by logistic regression (with no regular- ization)?
© A: w = 1, b = 1
© B: w = 0, b = 1
© C: w = 1, b = 0
D: w = ∞, b = 0
(6) [4 pts] Below are some choices you might make while training a neural network. Select all of the options that will generally make it more difficult for your network to achieve high accuracy on the test data.
(7) [4 pts] To the left of each graph below is a number. Select the choices for which the number is the multiplicity of the eigenvalue zero in the Laplacian matrix of the graph.
The multiplicity is equal to the number of connected components in the graph.
(8) [4 pts] Given the spectral graph clustering optimization problem Find y that minimizes y>^ Ly subject to y>y = n and 1 >y = 0, which of the following optimization problems produce a vector y that leads to the same sweep cut as the optimization problem above? M is a diagonal mass matrix with different masses on the diagonal.
Minimize y>^ Ly subject to y>y = 1 and 1 >y = 0
Minimize y>^ Ly subject to ∀i, yi = 1 or yi = − 1 and 1 >y = 0
Minimize y>^ Ly/(y>y) subject to 1 >y = 0
Minimize y>^ Ly subject to y>^ My = 1 and 1 >^ My = 0
(9) [4 pts] Which of the following methods will cluster the data in panel (a) of the figure below into the two clusters (red circle and blue horizontal line) shown in panel (b)? Every dot in the circle and the line is a data point. In all the options that involve hierarchical clustering, the algorithm is run until we obtain two clusters.
© A: Hierarchical agglomerative clustering with Euclidean distance and complete linkage
B: Hierarchical agglomerative clustering with Euclidean distance and single linkage
© C: Hierarchical agglomerative clustering with Euclidean distance and centroid linkage
© D: k-means clustering with k = 2
Single linkage uses the minimum distance between two clusters as a metric for merging clusters. Since the two clusters are densely packed with points and the minimum distance between the two clusters is greater than the within-cluster distances between points, single linkage doesn’t link the circle to the line until the very end.
The other three methods will all join some of the points at the left end of the line with the circle, before they are joined with the right end of the line.
(13) [4 pts] Suppose we are doing ordinary least-squares linear regression with a fictitious dimension. Which of the following changes can never make the cost function’s value on the training data smaller?
A: Discard the fictitious dimension (i.e., don’t append a 1 to every sample point).
© B: Append quadratic features to each sample point.
C: Project the sample points onto a lower-dimensional subspace with PCA (without changing the labels) and perform regression on the projected points.
D: Center the design matrix (so each feature has mean zero).
A: Correct. Discarding the fictitious dimension forces the linear regression function to be zero at the origin, which may increase the cost function but can never decrease it.
B: Incorrect. Added quadratic features often help to fit the data better.
C: Correct. Regular OLS is at least as expressive. Projecting the points may incrase the cost function but can never decrease it. Centering features doesn’t matter so WLOG assume X has centered features. If the full SVD is X = UΣV>, then projecting onto a k-dimensional subspace gives Xk = UΣkV>. If wk is a solution for the PCA-projected OLS, we can take w = Vz where z is the first k elements of V>wk with the rest zero, and get Xkwk = Xw.
D: Correct. Since we’re using a fictitious dimension, translating the points does not affect the cost of the optimal regression function (which translates with the points).
(14) [4 pts] Which of the following are true about principal components analysis (PCA)? Assume that no two eigenvectors of the sample covariance matrix have the same eigenvalue.
A: Appending a 1 to the end of every sample point doesn’t change the results of performing PCA (except that the useful principal component vectors have an extra 0 at the end, and there’s one extra useless component with eigenvalue zero).
B: If you use PCA to project d-dimensional points down to j principal coordinates, and then you run PCA again to project those j-dimensional coordinates down to k principal coordinates, with d > j > k, you always get the same result as if you had just used PCA to project the d-dimensional points directly down to k principle coordinates.
© C: If you perform an arbitrary rigid rotation of the sample points as a group in feature space before performing PCA, the principal component directions do not change.
D: If you perform an arbitrary rigid rotation of the sample points as a group in feature space before performing PCA, the largest eigenvalue of the sample covariance matrix does not change.
Appending an extra dimension with the same values introduces no variance in the extra dimension, so PCA will ignore that dimension. PCA discards the eigenvector directions associated with the largest eigenvalues; as the eigenvectors are mutually orthogonal, this does not affect the variance in the surviving dimensions, so your results depend solely on how many directions you discard. Rotating the sample points rotates the principal components, but it doesn’t change the variance along each of those (rotated) component directions.
(15) [4 pts] Consider running a single iteration of AdaBoost on three sample points, starting with uniform weights on the sample points. All the ground truth labels and predictions are either +1 or −1. In the table below, some values have been omitted. Which of the following statements can we say with certainty?
True Label Classifier Prediction Initial Weight Updated Weight X 1 − 1 − 1 1 / 3? X 2? + 1 1 / 3
A: X 1 ’s updated weight is
© B: X 3 ’s classifier prediction is − 1
C: X 2 is misclassified
© D: X 3 is misclassified
In the AdaBoost algorithm, all correctly classified points have their weights changed by the same multiplicative factor. Since we observe two different updated weights, we know one of x 2 or x 3 is correctly classified, and the other is mis- classified. Since x 1 is correctly classified, the error rate is err = 1 /3. As the error rate is less than 1/2, the weights of correctly classified points will decrease and the weights of misclassified points will increase. Hence, X 2 is misclassified and X 3 is correctly classified. As X 1 is correctly classified, it has the same updated weight as X 3. But we can’t tell what X 3 ’s classifier prediction is; only that it is correctly classified. As an aside, we can confirm the multipliers used for reweighting of misclassified and correctly classified points (in that order): √ err 1 − err
1 − err err
(16) [4 pts] Consider running the hierarchical agglomerative clustering algorithm on the following set of four points in R^2 , breaking ties arbitrarily. If we stop when only two clusters remain, which of the following linkage methods ensures the resulting clusters are balanced (each have two sample points)? Select all that apply.
Consider the following design matrix, representing four sample points Xi ∈ R^2.
We want to represent the data in only one dimension, so we turn to principal components analysis (PCA).
(1) [5 pts] Compute the unit-length principal component directions of X, and state which one the PCA algorithm would choose if you request just one principal component. Please provide an exact answer, without approximation. (You will need to use the square root symbol.) Show your work!
We center X, yielding
Then ˙X>^ X˙ =
. (Divide by 4 if you want the sample covariance matrix. But we don’t care about the magnitude.)
Its eigenvectors are [1/
2]>^ with eigenvalue 16 and [1/
2]>^ with eigenvalue 4. The former eigenvector is chosen.
(Negated versions of these vectors also get full points.)
(2) [5 pts] The plot below depicts the sample points from X. We want a one-dimensional representation of the data, so draw the principal component direction (as a line) and the projections of all four sample points onto the principal direction. Label each projected point with its principal coordinate value (where the origin’s principal coordinate is zero). Give the principal coordinate values exactly.
The principal coordinates are √^12 , √^52 , √^52 , and √^92. (Alternatively, all of these could be negative, but they all have to have the
same sign.)
(3) [4 pts] The plot below depicts the sample points from X rotated 30 degrees counterclockwise about the origin. As in part (b), identify the principal component direction that the PCA algorithm would choose and draw it (as a line) on the plot. Also draw the projections of the rotated points onto the principal direction. Label each projected point with the exact value of its principal coordinate.
In this question we investigate whether students will pass or fail CS 189 based on whether or not they studied, cheated, and slept well before the exam. You are given the following data for five students. There are three features, “Studied,” “Slept,” and “Cheated.” The column “Result” shows the label we want to predict.
Studied Slept Cheated Result Student 1 Yes No No Passed Student 2 Yes No Yes Failed Student 3 No Yes No Failed Student 4 Yes Yes Yes Failed Student 5 Yes Yes No Passed
(1) [4 pts] What is the entropy H(Result) at the root node? (There is no need to compute the exact number; you may write it as an arithmetic expression.)
H(Result) = −
log 2
log 2
(2) [5 pts] Draw the decision tree where every split maximizes the information gain. (An actual drawing, please; a written description does not suffice.) Do not perform a split on a pure leaf or if the split will produce an empty child; otherwise, split. Explain (with numbers) why you chose the splits you chose.
A tree that first splits on “Cheated” and then “Studied.”
(3) [2 pts] Did the tree you built implicitly perform feature subset selection? Explain.
Yes, because it does not use the feature “Slept.”
(4) [3 pts] Suppose you have a sample of n students for some large n, with the same three features. Assuming that we use a reasonably efficient algorithm to build the tree (as discussed in class), what is the worst-case running time to build the decision tree? (Write your answer in the simplest asymptotic form possible.) Why?
We have 3 binary features, so the tree’s depth cannot exceed 3 and each sample point participates in at most four treenodes. Hence, it cannot take more than Θ(n) time to build the tree.
Figure 1: An undirected, weighted graph in which all vertices have mass 1. The numbers inside the vertices are their indices (not masses).
In this problem, we approximate the sparsest cut of the graph above with the spectral graph clustering algorithm. Recall the spectral graph clustering optimization objective is to find y that minimizes y>^ Ly subject to y>y = 6 and 1 >y = 0.
(1) [4 pts] Write out the Laplacian matrix L.
(2) [3 pts] What is the rank of L? Explain your answer.
5, because the Laplacian matrix of a connected graph has one and only one eigenvector with eigenvalue zero.
(3) [4 pts] L has the following six unit eigenvectors, listed in random order. Write down the Fiedler vector. Then explain how you can tell which one is the Fiedler vector without doing a full eigendecomposition computation. (There are several ways to see this; describe one.)
© [0. 36 , − 0. 58 , 0. 61 , − 0. 4 , 0. 04 , − 0 .03]
The Fiedler vector is v 2 = [0. 36 , 0. 34 , 0. 25 , 0. 19 , − 0. 55 , − 0 .6]. Since we know these are all eigenvectors of the Laplacian matrix L, one way to identify it is to explicitly multiply the first row of L by an eigenvector, and divide by the first component of the eigenvector to reveal its eigenvalue. (The Fiedler vector has eigenvalue λ 2 = 6 .5; all the others except v 1 have larger
In this problem, we shall consider the same graph as in the previous question, but we use multiple eigenvectors to perform 3-cluster clustering with the algorithm of Ng, Jordan, and Weiss (as opposed to the 2-cluster clustering we performed in the last question).
(1) [4 pts] Based on the six eigenvectors of L given in the previous question, write down the spectral vector (as defined in the lecture notes) for each vertex 1 ,... , 6 in that order.
The matrix of spectral vectors is
(2) [8 pts] We shall now cluster the six raw, unnormalized spectral vectors obtained above using hierarchical agglomerative clustering with the Euclidean distance metric and single linkage. In contrast to what was discussed in class, we are not normalizing the six spectral vectors (because we don’t want you to work that hard). Draw the complete single linkage dendrogram on paper. The six integer points on the x-axis, 1,... , 6, should represent the vertices of the graph in the order of their indices. The y-axis should indicate the linkage distances, as is standard for dendrograms. The numerical distance at which each fusion happens should be clearly marked on your figure.
Points 5 and 6 merge first; the Euclidean distance between them is 0.06. Points 3 and 4 merge next; the Euclidean distance between them is 0.2. Points 1 and 2 merge next; the Euclidean distance between them is 0.24. The single linkage distance between { 1 , 2 } and { 3 , 4 } is 0.76. The single linkage distance between { 1 , 2 } and { 5 , 6 } is 0.93. That between { 3 , 4 } and { 5 , 6 } is 0 .94. Therefore, the fourth merger is between { 1 , 2 } and { 3 , 4 }. The clusters after the fourth merger are { 1 , 2 , 3 , 4 } and { 5 , 6 }, matching what we obtained in the previous question. { 1 , 2 , 3 , 4 } and { 5 , 6 } merge at 0.93. The green dotted line indicates the 2-cluster clustering. The red dotted line indicates the 3-cluster clustering. (Note tha students aren’t asked to specify those lines.)
(1) [4 pts] Consider a single unit in a neural network that receives two binary inputs x 1 , x 2 ∈ { 0 , 1 }^2 and computes a linear combination followed by a threshold activation function, namely,
σ(z) =
1 , z ≥ 0 , 0 otherwise.
The unit is illustrated below. We have chosen a bias term of b = 5. Provide values for the two weights w 1 and w 2 that allow you to compute the NAND function (which is 0 if and only if both inputs are 1).
w 1 = −3, w 2 = −3 will work.
(2) [6 pts] We are drawing sample points from a distribution with the probability density function (PDF) f (x) = 12 e−|x−μ|, but we do not know the mean μ ∈ R. We decide to estimate μ with maximum likelihood estimation (MLE). Unfortunately, we have only two sample points X 1 , X 2 ∈ R. Derive the likelihood and the log-likelihood for this problem. Then show that every value of μ between X 1 and X 2 is a maximum likelihood estimate.
The likelihood is
L(μ; X 1 , X 2 ) =
e−|X^1 −μ|e−|X^2 −μ|,
and the log-likelihood is `(μ; X 1 , X 2 ) = −|X 1 − μ| − |X 2 − μ| − ln 4.
For any μ between X 1 and X 2 (inclusive), the log-likelihood is −|X 1 − X 2 | − ln 4. For any μ outside that range, it is lesser. (For example if μ is less than min{X 1 , X 2 }, then the log-likelihood is −|X 1 − X 2 | − 2 |μ − min{X 1 , X 2 }| − ln 4).
The Leave-One-Out error is defined to be
n
∑^ n
i= 1
(wi^ · Xi − yi)^2 =
n
∑^ n
i= 1
(w(i)^ · Xi − yi)^2.
The LOO error is often an excellent estimator for the regression loss on unseen data. In general, the computation of LOO error can be very costly because it requires training the algorithm n times. But for dual ridge regression, remarkably, the LOO error can be computed by training the algorithm only once! Let’s see how to compute the terms in the summation quickly.
(4) [4 pts] Show that w(i)^ ·^ Xi −^ yi =^
w∗^ · Xi − yi 1 − (K + λI)− i 1 Ki
From part (c), we have
(w(i)^ · Xi − yi) − (w∗^ · Xi − yi) = (w(i)^ · Xi − yi)(K + λI)− i 1 Ki (w(i)^ · Xi − yi)(1 − K + λI)− i 1 Ki) = w∗^ · Xi − yi
w(i)^ · Xi − yi = w∗^ · Xi − yi 1 − (K + λI)− i 1 Ki
Postscript: We can add the kernel trick to this method if we want; it adds no difficulties, though for speed we usually want to use the kernel function to compute K and each w∗^ · Xi. The technique also requires us to compute the diagonal of (K + λI)−^1 K, which is probably best done by a Cholesky factorization of (K + λI)−^1 and backsubstitution.