[Solved] CS229 Problem #1- Supervised Learning

$25

File Name: CS229_Problem_#1-_Supervised_Learning.zip
File Size: 348.54 KB

SKU: [Solved] CS229 Problem #1- Supervised Learning Category: Tag:
5/5 - (1 vote)

Notes: (1) These questions require thought, but do not require long answers. Please be as concise as possible. (2) If you have a question about this homework, we encourage you to post your question on our Piazza forum, at https://piazza.com/class#fall2012/cs229. (3) If you missed the first lecture or are unfamiliar with the collaboration or honor code policy, please read the policy on Handout #1 (available from the course website) before starting work. (4) For problems that require programming, please include in your submission a printout of your code (with comments) and any figures that you are asked to plot. (5) Please indicate the submission time and number of late dates clearly in your submission.

SCPD students: Please email your solutions to [email protected] with the subject line Problem Set 1 Submission. If you are writing your solutions out by hand, please write clearly and in a reasonably large font using a dark pen to improve legibility.

1.Logistic regression

(a) [10 points] Consider the log-likelihood function for logistic regression:

m

() = Xy(i) logh(x(i)) + (1 y(i))log(1 h(x(i)))

i=1

Find the Hessian H of this function, and show that for any vector z, it holds true that

zTHz 0.

[Hint: You might want to start by showing the fact that Pi Pj zixixjzj = (xTz)2

0.]

Remark: This is one of the standard ways of showing that the matrix H is negative semi-definite, written H 0. This implies that is concave, and has no local maxima other than the global one.[1] If you have some other way of showing H 0, youre also welcome to use your method instead of the one above.

  • [10 points] On the Leland system, the files /afs/ir/class/cs229/ps/ps1/q1x.dat and /afs/ir/class/cs229/ps/ps1/q1y.dat contain the inputs (x(i) R[2]) and outputs (y(i) {0,1}) respectively for a binary classification problem, with one training example per row. Implement2 Newtons method for optimizing (), and apply it to fit a logistic regression model to the data. Initialize Newtons method with = ~0 (the vector of all zeros). What are the coefficients resulting from your fit? (Remember to include the intercept term.)
  • [5 points] Plot the training data (your axes should be x1 and x2, corresponding to the two coordinates of the inputs, and you should use a different symbol for each point plotted to indicate whether that example had label 1 or 0). Also plot on the same figure the decision boundary fit by logistic regression. (I.e., this should be a straight line showing the boundary separating the region where h(x) > 0.5 from where h(x) 0.)

2. Locally weighted linear regression

Consider a linear regression problem in which we want to weight different training examples differently. Specifically, suppose we want to minimize

.

In class, we worked out what happens for the case where all the weights (the w(i)s) are the same. In this problem, we will generalize some of those ideas to the weighted setting, and also implement the locally weighted linear regression algorithm.

  • [2 points] Show that J() can also be written

J() = (X ~y)TW(X ~y)

for an appropriate diagonal matrix W, and where X and ~y are as defined in class. State clearly what W is.

  • [7 points] If all the w(i)s equal 1, then we saw in class that the normal equation is

XTX = XT~y,

and that the value of that minimizes J() is given by (XTX)1XT~y. By finding the derivative J() and setting that to zero, generalize the normal equation to this weighted setting, and give the new value of that minimizes J() in closed form as a function of X, W and ~y.

  • [6 points] Suppose we have a training set {(x(i),y(i)); i = 1,m} of m independent examples, but in which the y(i)s were observed with differing variances. Specifically, suppose that

I.e., y(i) has mean Tx(i) and variance ((i))2 (where the (i)s are fixed, known, constants). Show that finding the maximum likelihood estimate of reduces to solving a weighted linear regression problem. State clearly what the w(i)s are in terms of the (i)s.

  • On the Leland computer system, the files /afs/ir/class/cs229/ps/ps1/q2x.dat and /afs/ir/class/cs229/ps/ps1/q2y.dat contain the inputs (x(i)) and outputs (y(i)) for a regression problem, with one training example per row.
    1. Implement (unweighted) linear regression (y = Tx) on this dataset (using the normal equations), and plot on the same figure the data and the straight line resulting from your fit. (Remember to include the intercept term.)
    2. Implement locally weighted linear regression on this dataset (using theweighted normal equations you derived in part (b)), and plot on the same figure the data and the curve resulting from your fit. When evaluating h() at a query point x, use weights

,

with a bandwidth parameter = 0.8. (Again, remember to include the intercept term.)

  • [3 points] Repeat (ii) four times, with = 0.1,0.3,2 and 10. Comment briefly on what happens to the fit when is too small or too large.
  1. ] Poisson regression and the exponential family (a) [5 points] Consider the Poisson distribution parameterized by :

.

Show that the Poisson distribution is in the exponential family, and clearly state what are b(y), , T(y), and a().

  • Consider performing regression using a GLM model with a Poisson response variable. What is the canonical response function for the family? (You may use the fact that a Poisson random variable with parameter has mean .)
  • For a training set {(x(i),y(i)); i = 1,,m}, let the log-likelihood of an example be logp(y(i)|x(i);). By taking the derivative of the log-likelihood with respect to j, derive the stochastic gradient ascent rule for learning using a GLM model with Poisson responses y and the canonical response function.
  • Consider using GLM with a response variable from any member of the exponential family in which T(y) = y, and the canonical response function for the family. Show that stochastic gradient ascent on the log-likelihood logp(~y|X,) results in the update rule i := i (h(x) y)xi.

4. [15 points] Gaussian discriminant analysis

Suppose we are given a dataset {(x(i),y(i)); i = 1,,m} consisting of m independent examples, where x(i) Rn are n-dimensional vectors, and y(i) {0,1}. We will model the joint distribution of (x,y) according to:

Here, the parameters of our model are , , 0 and 1. (Note that while therere two different mean vectors 0 and 1, theres only one covariance matrix .)

  • [5 points] Suppose we have already fit , , 0 and 1, and now want to make a prediction at some new query point x. Show that the posterior distribution of the label at x takes the form of a logistic function, and can be written

,

where is some appropriate function of ,,0,1. (Note: To get your answer into the form above, for this part of the problem only, you may have to redefine the x(i)s to be n + 1-dimensional vectors by adding the extra coordinate = 1, like we did in class.)

  • [10 points] For this part of the problem only, you may assume n (the dimension of x) is 1, so that = [2] is just a real number, and likewise the determinant of is given by || = 2. Given the dataset, we claim that the maximum likelihood estimates of the parameters are given by

m

01 == == 1 y(i) = 1m X { }i=1m { (i) = 0}x(i)1 yi=1m { (i) = 0}1 yPi=1m { (i) = 1}x(i)1 yi=11 yPmi=1 { (i) = 1}1 Xm (i) y(i))(x(i) y(i))T (x

1

m

i=1

The log-likelihood of the data is

m

(,0,1,) = logYp(x(i),y(i);,0,1,) i=1
= m logYp(x(i)|y(i);0,1,)p(y(i);).

i=1

By maximizing with respect to the four parameters, prove that the maximum likelihood estimates of , 0,1, and are indeed as given in the formulas above. (You may assume that there is at least one positive and one negative example, so that the denominators in the definitions of 0 and 1 above are non-zero.)

(c) Without assuming that n = 1, show that the maximum likelihood estimates of ,0,1, and are as given in the formulas in part (b). [Note: If youre fairly sure that you have the answer to this part right, you dont have to do part (b), since thats just a special case.]

5. Linear invariance of optimization algorithms

Consider using an iterative optimization algorithm (such as Newtons method, or gradient descent) to minimize some continuously differentiable function f(x). Suppose we initialize the algorithm at x(0) = ~0. When the algorithm is run, it will produce a value of x Rn for each iteration: x(1),x(2),.

Now, let some non-singular square matrix A Rnn be given, and define a new function g(z) = f(Az). Consider using the same iterative optimization algorithm to optimize g (with initialization z(0) = ~0). If the values z(1),z(2), produced by this method necessarily satisfy z(i) = A1x(i) for all i, we say this optimization algorithm is invariant to linear reparameterizations.

  • [9 points] Show that Newtons method (applied to find the minimum of a function) is invariant to linear reparameterizations. Note that since z(0) = ~0 = A1x(0), it is sufficient to show that if Newtons method applied to f(x) updates x(i) to x(i+1), then Newtons method applied to g(z) will update z(i) = A1x(i) to z(i+1) = A1x(i+1).[3]
  • [3 points] Is gradient descent invariant to linear reparameterizations? Justify youranswer.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS229 Problem #1- Supervised Learning
$25