Docsity

CS 189 Spring 2016 Introduction to Machine Learning, Study notes of Machine Learning

Toggle sidebar
bg1
CS 189
Spring 2016 Introduction to
Machine Learning Final
•Please do not open the exam before you are instructed to do so.
•The exam is closed book, closed notes except your two-page cheat sheet.
•Electronic devices are forbidden on your person, including cell phones, iPods, headphones, and laptops.
Turn your cell phone off and leave all electronics at the front of the room, or risk getting a zero on
the exam.
•You have 3 hours.
•Please write your initials at the top right of each page (e.g., write “JS” if you are Jonathan Shewchuk). Finish
this by the end of your 3 hours.
•Mark your answers on front of each page, not the back. We will not scan the backs of each page, but you may
use them as scratch paper. Do not attach any extra sheets.
•The total number of points is 150. There are 30 multiple choice questions worth 3 points each, and 6 written
questions worth a total of 60 points.
•For multiple-choice questions, fill in the boxes for ALL correct choices: there may be more than one correct
choice, but there is always at least one correct choice. NO partial credit on multiple-choice questions: the
set of all correct answers must be checked.
First name
Last name
SID
First and last name of student to your left
First and last name of student to your right
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download CS 189 Spring 2016 Introduction to Machine Learning and more Study notes Machine Learning in PDF only on Docsity!

CS 189

Spring 2016

Introduction to

Machine Learning Final

  • Please do not open the exam before you are instructed to do so.
  • The exam is closed book, closed notes except your two-page cheat sheet.
  • Electronic devices are forbidden on your person, including cell phones, iPods, headphones, and laptops. Turn your cell phone off and leave all electronics at the front of the room, or risk getting a zero on the exam.
  • You have 3 hours.
  • Please write your initials at the top right of each page (e.g., write “JS” if you are Jonathan Shewchuk). Finish this by the end of your 3 hours.
  • Mark your answers on front of each page, not the back. We will not scan the backs of each page, but you may use them as scratch paper. Do not attach any extra sheets.
  • The total number of points is 150. There are 30 multiple choice questions worth 3 points each, and 6 written questions worth a total of 60 points.
  • For multiple-choice questions, fill in the boxes for ALL correct choices: there may be more than one correct choice, but there is always at least one correct choice. NO partial credit on multiple-choice questions: the set of all correct answers must be checked.

First name

Last name

SID

First and last name of student to your left

First and last name of student to your right

Q1. [90 pts] Multiple Choice

Check the boxes for ALL CORRECT CHOICES. Every question should have at least one box checked. NO PARTIAL CREDIT: the set of all correct answers (only) must be checked.

(1) [3 pts] What strategies can help reduce overfitting in decision trees?

 Pruning

 Make sure each leaf node is one pure class

 Enforce a minimum number of samples in leaf nodes

 Enforce a maximum depth for the tree

(2) [3 pts] Which of the following are true of convolutional neural networks (CNNs) for image analysis?

 Filters in earlier layers tend to include edge detectors

 Pooling layers reduce the spatial resolution of the image

 They have more parameters than fully- connected networks with the same number of lay- ers and the same numbers of neurons in each layer

 A CNN can be trained for unsupervised learn- ing tasks, whereas an ordinary neural net cannot

(3) [3 pts] Neural networks

 optimize a convex cost function

 can be used for regression as well as classifica- tion

 always output values between 0 and 1

 can be used in an ensemble

(4) [3 pts] Which of the following are true about generative models?

 They model the joint distribution P (class = C AND sample = x)

 They can be used for classification

 The perceptron is a generative model

 Linear discriminant analysis is a generative model

(5) [3 pts] Lasso can be interpreted as least-squares linear regression where

 weights are regularized with the ` 1 norm

 weights are regularized with the ` 2 norm

 the weights have a Gaussian prior

 the solution algorithm is simpler

(6) [3 pts] Which of the following methods can achieve zero training error on any linearly separable dataset?

 Decision tree

 Hard-margin SVM

 15-nearest neighbors

 Perceptron

(7) [3 pts] The kernel trick

 can be applied to every classification algorithm

 changes ridge regression so we solve a d × d linear system instead of an n × n system, given n sample points with d features

 is commonly used for dimensionality reduction

 exploits the fact that in many learning al- gorithms, the weights can be written as a linear combination of input points

(15) [3 pts] Which value of k in the k-nearest neighbors algorithm generates the solid decision boundary depicted here? There are only 2 classes. (Ignore the dashed line, which is the Bayes decision boundary.)

 k = 1

 k = 10

 k = 2

 k = 100

(16) [3 pts] Consider one layer of weights (edges) in a convolutional neural network (CNN) for grayscale images, connecting one layer of units to the next layer of units. Which type of layer has the fewest parameters to be learned during training? (Select one.)

 A convolutional layer with 10 3 × 3 filters

 A max-pooling layer that reduces a 10 × 10 image to 5 × 5

 A convolutional layer with 8 5 × 5 filters

 A fully-connected layer from 20 hidden units to 4 output units

(17) [3 pts] In the kernelized perceptron algorithm with learning rate  = 1, the coefficient ai corresponding to a training example xi represents the weight for K(xi, x). Suppose we have a two-class classification problem with yi ∈ { 1 , − 1 }. If yi = 1, which of the following can be true for ai?

 ai = − 1

 ai = 0

 ai = 1

 ai = 5

(18) [3 pts] Suppose you want to split a graph G into two subgraphs. Let L be G’s Laplacian matrix. Which of the following could help you find a good split?

 The eigenvector corresponding to the second- largest eigenvalue of L

 The eigenvector corresponding to the second- smallest eigenvalue of L

 The left singular vector corresponding to the second-largest singular value of L

 The left singular vector corresponding to the second-smallest singular value of L

(19) [3 pts] Which of the following are properties that a kernel matrix always has?

 Invertible

 At least one negative eigenvalue

 All the entries are positive

 Symmetric

(20) [3 pts] How does the bias-variance decomposition of a ridge regression estimator compare with that of ordinary least squares regression? (Select one.)

 Ridge has larger bias, larger variance

 Ridge has larger bias, smaller variance

 Ridge has smaller bias, larger variance

 Ridge has smaller bias, smaller variance

(21) [3 pts] Both PCA and Lasso can be used for feature selection. Which of the following statements are true?

 Lasso selects a subset (not necessarily a strict subset) of the original features

 PCA produces features that are linear combi- nations of the original features

 PCA and Lasso both allow you to specify how many features are chosen

 PCA and Lasso are the same if you use the kernel trick

(22) [3 pts] Which of the following are true about forward subset selection?

 O(2d) models must be trained during the al- gorithm, where d is the number of features

 It greedily adds the feature that most improves cross-validation accuracy

 It finds the subset of features that give the lowest test error

 Forward selection is faster than backward se- lection if few features are relevant to prediction

(23) [3 pts] You’ve just finished training a random forest for spam classification, and it is getting abnormally bad performance on your validation set, but good performance on your training set. Your implementation has no bugs. What could be causing the problem?

 Your decision trees are too deep

 You are randomly sampling too many features when you choose a split

 You have too few trees in your ensemble

 Your bagging implementation is randomly sampling sample points without replacement

(24) [3 pts] Consider training a decision tree given a design matrix X =

 and labels^ y^ =

. Let^ f^1 denote

feature 1, corresponding to the first column of X, and let f 2 denote feature 2, corresponding to the second column. Which of the following splits at the root node gives the highest information gain? (Select one.)

 f 1 > 2

 f 1 > 4

 f 2 > 3

 f 2 > 6

(25) [3 pts] In terms of the bias-variance decomposition, a 1-nearest neighbor classifier has than a 3-nearest neighbor classifier.

 higher variance

 lower variance

 higher bias

 lower bias

Q2. [8 pts] Feature Selection

A newly employed former CS 189/289A student trains the latest Deep Learning classifier and obtains state-of-the-art accuracy. However, the classifier uses too many features! The boss is overwhelmed and asks for a model with fewer features.

Let’s try to identify the most important features. Start with a simple dataset in R^2.

(1) [4 pts] Describe the training error of a Bayes optimal classifier that can see only the first feature of the data. Describe the training error of a Bayes optimal classifier that can see only the second feature.

The first feature yields a training error of 50% (like random guessing). The second feature offers a training error of zero.

(2) [4 pts] Based on this toy example, the student decides to fit a classifier on each feature individually, then rank the features by their classifier’s accuracy, take the best k features, and train a new classifier on those k features. We call this approach variable ranking. Unfortunately, the classifier trained on the best k features obtains horrible accuracy, unless k is very close to d, the original number of features! Construct a toy dataset in R^2 for which variable ranking fails. In other words, a dataset where a variable is useless by itself, but potentially useful alongside others. Use + for data points in Class 1, and O for data points in Class 2.

An XOR Dataset is unpredictable with either feature. (This extends to n-dimensions, with the n-bit parity string.)

Q3. [10 pts] Gradient Descent for k-means Clustering

Recall the loss function for k-means clustering with k clusters, sample points x 1 , ..., xn, and centers μ 1 , ..., μk:

L =

∑^ k

j=

xi∈Sj

‖xi − μj ‖^2 ,

where Sj refers to the set of data points that are closer to μj than to any other cluster mean.

(1) [4 pts] Instead of updating μj by computing the mean, let’s minimize L with batch gradient descent while holding the sets Sj fixed. Derive the update formula for μ 1 with learning rate (step size) .

∂L

∂μ 1

∂μ 1

xi∈S 1

(xi − μ 1 )>(xi − μ 1 )

xi∈S 1

2(μ 1 − xi).

Therefore the update formula is μ 1 ← μ 1 + 

xi∈S 1

(xi − μ 1 ).

(Note: writing 2 instead of  is fine.)

(2) [2 pts] Derive the update formula for μ 1 with stochastic gradient descent on a single sample point xi. Use learning rate . μ 1 ← μ 1 + (xi − μ 1 ) if xi ∈ S 1 , otherwise no change.

(3) [4 pts] In this part, we will connect the batch gradient descent update equation with the standard k-means algorithm. Recall that in the update step of the standard algorithm, we assign each cluster center to be the mean (centroid) of the data points closest to that center. It turns out that a particular choice of the learning rate  (which may be different for each cluster) makes the two algorithms (batch gradient descent and the standard k-means algorithm) have identical update steps. Let’s focus on the update for the first cluster, with center μ 1. Calculate the value of  so that both algorithms perform the same update for μ 1. (If you do it right, the answer should be very simple.) In the standard algorithm, we assign μ 1 ←

xi∈S 1 1 |S 1 | xi. Comparing to the answer in (1), we set

xi∈S 1

1 |S 1 | xi^ =^ μ^1 +^ ^

xi∈S 1 (xi^ −^ μ^1 ) and solve for^ . ∑

xi∈S 1

|S 1 |

xi −

xi∈S 1

|S 1 |

μ 1 = 

xi∈S 1

(xi − μ 1 )

∑

xi∈S 1

|S 1 |

(xi − μ 1 ) = 

xi∈S 1

(xi − μ 1 ).

Thus  = (^) |S^11 |. (Note: answers that differ by a constant factor are fine if consistent with answer for (1).)

Q5. [12 pts] Let’s PCA

You are given a design matrix X =

. Let’s use PCA to reduce the dimension from 2 to 1.

(1) [6 pts] Compute the covariance matrix for the sample points. (Warning: Observe that X is not centered.) Then compute the unit eigenvectors, and the corresponding eigenvalues, of the covariance matrix. Hint: If you graph the points, you can probably guess the eigenvectors (then verify that they really are eigenvectors).

The covariance matrix is X>X =

[

]

Its unit eigenvectors are

[ 1

√ 12 √ 2

]

with eigenvalue 2 and

[ 1

√ 2 − √^12

]

with eigenvalue 162. (Note: either eigenvector

can be replaced with its negation.)

(2) [3 pts] Suppose we use PCA to project the sample points onto a one-dimensional space. What one-dimensional subspace are we projecting onto? For each of the four sample points in X (not the centered version of X!), write the coordinate (in principal coordinate space, not in R^2 ) that the point is projected to.

We are projecting onto the subspace spanned by

[

√^1 2 − √^12

]

. (Equivalently, onto the space spanned by

[

]

. Equiva-

lently, onto the line x + y = 0.) The projections are (6, −4) → √^102 , (− 3 , 5) → − √^82 , (− 2 , 6) → − √^82 , (7, −3) → √^102.

(3) [3 pts] Given a design matrix X that is taller than it is wide, prove that every right singular vector of X with singular value σ is an eigenvector of the covariance matrix with eigenvalue σ^2.

If v is a right singular vector of X, then there is a singular value decomposition X = U DV >^ such that v is a column of V. Here each of U and V has orthonormal columns, V is square, and D is square and diagonal. The covariance matrix is X>X = V DU >U DV >^ = V D^2 V >. This is an eigendecomposition of X>X, so each singular vector in V with singular value σ is an eigenvector of X>X with eigenvalue σ^2.

Q6. [10 pts] Trees

6

2

3

7

14

13

12

15 17

10

1 5

6 8 11

4

9

16

1

12 10 16 13

9 14 15 11 17

2 3 4 8 7

5

(1) [5 pts] Above, we have two depictions of the same k-d tree, which we have built to solve nearest neighbor queries. Each node of the tree at right represents a rectangular box at left, and also stores one of the sample points that lie inside that box. (The root node represents the whole plane R^2 .) If a treenode stores sample point i, then the line passing through point i (in the diagram at left) determines which boxes the child treenodes represent. Simulate running an exact 1-nearest neighbor query, where the bold X is the query point. Recall that the query algorithm visits the treenodes in a smart order, and keeps track of the nearest point it has seen so far.

  • Write down the numbers of all the sample points that serve as the “nearest point seen so far” sometime while the query algorithm is running, in the order they are encountered.
  • Circle all the subtrees in the k-d tree at upper right that are never visited during this query. (This is why k-d tree search is usually faster than exhaustive search.)

Nearest point seen so far: first 5, then 12, then 10.

The unvisited subtrees are rooted at 2, 13, 7, and 17.

(2) [5 pts] We are building a decision tree for a 2-class classification problem. We have n training points, each having d real-valued features. At each node of the tree, we try every possible univariate split (i.e. for each feature, we try every possible splitting value for that feature) and choose the split that maximizes the information gain. Explain why it is possible to build the tree in O(ndh) time, where h is the depth of the tree’s deepest node. Your explanation should include an analysis of the time to choose one node’s split. Assume that we can radix sort real numbers in linear time.

Consider choosing the split at a node whose box contains n′^ sample points. For each of the d features, we can sort the sample points in O(n′d) time. Then we can compute the entropy for the first split (separating the first sample in the sorted list from the others) in O(n′) time, then we can walk through the list and update the entropy for each successive split in O(1) time, summing to a total of O(n′) time for each of the d features. So it takes O(n′d) time overall to choose a split.

Each sample point participates in at most h treenodes, so each sample point contributes at most dh to the running time, for a total running time of at most O(ndh).