CSE/ISYE 6740 Homework 3 solution

$24.99

Original Work ?

Download Details:

  • Name: assignment3-wgueck.zip
  • Type: zip
  • Size: 656.10 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (5 votes)

1 Linear Regression [30 pts]
In class, we derived a closed form solution (normal equation) for linear regression problem: ˆθ = (XT X)
−1XT Y .
A probabilistic interpretation of linear regression tells us that we are relying on an assumption that each
data point is actually sampled from a linear hyperplane, with some noise. The noise follows a zero-mean
Gaussian distribution with constant variance. Specifically,
Y
i = θ
T Xi + 
i
(1)
where 
i ∼ N (0, σ2
I), θ ∈ R
d
, and {Xi
, Y i} is the i-th data point. In other words, we are assuming that
each every point is independent to each other and that every data point has same variance.
1https://matlab.mathworks.com/
2You can also use the environment for developing by registering online with your university email.
3Christopher M. Bishop, Pattern Recognition and Machine Learning, 2006, Springer.
1
(a) Using the normal equation, and the model (Eqn. 1), derive the expectation E[
ˆθ]. Note
that here X is fixed, and only Y is random, i.e. “fixed design” as in statistics. [6 pts]
(b) Similarly, derive the variance Var[
ˆθ]. [6 pts]
(c) Under the white noise assumption above, someone claims that ˆθ follows Gaussian distribution with mean and variance in (a) and (b), respectively. Do you agree with this claim? Why
or why not? [8 pts]
(d) Weighted linear regression
Suppose we keep the independence assumption but remove the same variance assumption. In other words,
data points would be still sampled independently, but now they may have different variance σi
. Thus, the
covariance matrix of Y would be still diagonal, but with different values:
Σ =





σ
2
1 0 . . . 0
0 σ
2
2
. . . 0
.
.
.
.
.
.
.
.
.
.
.
.
0 0 . . . σ2
n





. (2)
Derive the estimator ˆθ (similar to the normal equations) for this problem using matrix-vector notations with
Σ. [10 pts]
2 Ridge Regression [15 pts]
For linear regression, it is often assumed that y = θ
>x +  where θ, x ∈ R
m by absorbing the constant
term, and  ∼ N (0, σ2
) is a Gaussian random variable. Given n i.i.d samples (x
1
, y1
), …,(x
n, yn), we define
y = (y
1
, …, yn)
> and X = (x
1
, …, x
n)
>. Thus, we have y ∼ N (Xθ, σ2
I). Show that the ridge regression
estimate is the mean of the posterior distribution under a Gaussian prior θ ∼ N (0, τ 2
I). Find the explicit
relation between the regularization parameter λ in the ridge regression estimate of the parameter θ, and the
variances σ
2
, τ 2
.
3 Bayes Classifier
3.1 Bayes Classifier With General Loss Function
In class, we talked about the popular 0-1 loss function in which L(a, b) = 1 for a 6= b and 0 otherwise,
which means all wrong predictions cause equal loss. Yet, in many other cases including cancer detection,
the asymmetric loss is often preferred (misdiagnosing cancer as no-cancer is much worse). In this problem,
we assume to have such an asymmetric loss function where L(a, a) = L(b, b) = 0 and L(a, b) = p, L(b, a) =
q, p 6= q. Write down the the Bayes classifier f : X → Y for binary classification Y ∈ {−1, +1}. Simplify the
classification rule as much as you can. [20 pts]
3.2 Gaussian Class Conditional distribution
(a) Suppose the class conditional distribution is a Gaussian. Based on the general loss function in problem
3.1, write the Bayes classifier as f(X) = sign(h(X)) and simplify h as much as possible. What is the
geometric shape of the decision boundary? [10 pts]
2
(b) Repeat (a) but assume the two Gaussians have identical covariance matrices. What is the geometric
shape of the decision boundary? [10 pts]
(c) Repeat (a) but assume now that the two Gaussians have covariance matrix which is equal to the identity
matrix. What is the geometric shape of the decision boundary? [10 pts]
4 Logistic Regression
Logistic regression is named after the log-odds of success (the logit of the probability) defined as below:
ln 
P[Y = 1|X = x]
P[Y = 0|X = x]

where
P[Y = 1|X = x] = exp(w0 + w
T x)
1 + exp(w0 + wT x)
(a) Show that log-odds of success is a linear function of X. [6 pts]
(b) Show that the logistic loss L(z) = log (1 + exp(−z)) is a convex function. [9 pts]
5 Programming: Recommendation System [40 pts]
Personalized recommendation systems are used in a wide variety of applications such as electronic commerce,
social networks, web search, and more. Machine learning techniques play a key role to extract individual
preference over items. In this assignment, we explore this popular business application of machine learning,
by implementing a simple matrix-factorization-based recommender using gradient descent.
Suppose you are an employee in Netflix. You are given a set of ratings (from one star to five stars)
from users on many movies they have seen. Using this information, your job is implementing a personalized
rating predictor for a given user on unseen movies. That is, a rating predictor can be seen as a function
f : U × I → R, where U and I are the set of users and items, respectively. Typically the range of this
function is restricted to between 1 and 5 (stars), which is the the allowed range of the input.
Now, let’s think about the data representation. Suppose we have m users and n items, and a rating
given by a user on a movie. We can represent this information as a form of matrix, namely rating matrix M.
Suppose rows of M represent users, while columns do movies. Then, the size of matrix will be m × n. Each
cell of the matrix may contain a rating on a movie by a user. In M15,47, for example, it may contain a rating
on the item 47 by user 15. If he gave 4 stars, M15,47 = 4. However, as it is almost impossible for everyone to
watch large portion of movies in the market, this rating matrix should be very sparse in nature. Typically,
only 1% of the cells in the rating matrix are observed in average. All other 99% are missing values, which
means the corresponding user did not see (or just did not provide the rating for) the corresponding movie.
Our goal with the rating predictor is estimating those missing values, reflecting the user’s preference learned
from available ratings.
Our approach for this problem is matrix factorization. Specifically, we assume that the rating matrix M
is a low-rank matrix. Intuitively, this reflects our assumption that there is only a small number of factors
(e.g, genre, director, main actor/actress, released year, etc.) that determine like or dislike. Let’s define r as
3
the number of factors. Then, we learn a user profile U ∈ R
m×r and an item profile V ∈ R
n×r
. (Recall that
m and n are the number of users and items, respectively.) We want to approximate a rating by an inner
product of two length r vectors, one representing user profile and the other item profile. Mathematically, a
rating by user u on movie i is approximated by
Mu,i ≈
Xr
k=1
Uu,kVi,k. (3)
We want to fit each element of U and V by minimizing squared reconstruction error over all training data
points. That is, the objective function we minimize is given by
E(U, V ) = X
(u,i)∈M
(Mu,i − U
T
u Vi)
2 =
X
(u,i)∈M
(Mu,i −
Xr
k=1
Uu,kVi,k)
2
(4)
where Uu is the uth row of U and Vi
is the ith row of V . We observe that this looks very similar to the
linear regression. Recall that we minimize in linear regression:
E(θ) = Xm
i=1
(Y
i − θ
T x
i
)
2 =
Xm
i=1
(Y
i −
Xr
k=1
θkx
i
k
)
2
(5)
where m is the number of training data points. Let’s compare (4) and (5). Mu,i in (4) corresponds to Y
i
in (5), in that both are the observed labels. U
T
u Vi
in (4) corresponds to θ
T x
i
in (5), in that both are our
estimation with our model. The only difference is that both U and V are the parameters to be learned in
(4), while only θ is learned in (5). This is where we personalize our estimation: with linear regression, we
apply the same θ to any input x
i
, but with matrix factorization, a different profile Uu are applied depending
on who is the user u.
As U and V are interrelated in (4), there is no closed form solution, unlike linear regression case. Thus,
we need to use gradient descent:
Uv,k ← Uv,k − µ
∂E(U, V )
∂Uv,k
, Vj,k ← Vj,k − µ
∂E(U, V )
∂Vj,k
, (6)
where µ is a hyper-parameter deciding the update rate. It would be straightforward to take partial derivatives
of E(U, V ) in (4) with respect to each element Uv,k and Vj,k. Then, we update each element of U and V
using the gradient descent formula in (6).
(a) Derive the update formula in (6) by solving the partial derivatives. [10 pts]
(b) To avoid overfitting, we usually add regularization terms, which penalize for large values
in U and V . Redo part (a) using the regularized objective function below. [5 pts]
E(U, V ) = X
(u,i)∈M
(Mu,i −
Xr
k=1
Uu,kVi,k)
2 + λ
X
u,k
U
2
u,k + λ
X
i,k
V
2
i,k
(λ is a hyper-parameter controlling the degree of penalization.)
(c) Implement myRecommender.m by filling the gradient descent part.
You are given a skeleton code myRecommender.m. Using the training data rateMatrix, you will implement your own recommendation system of rank lowRank. The only file you need to edit and submit is
myRecommender.m. In the gradient descent part, repeat your update formula in (b), observing the average
reconstruction error between your estimation and ground truth in training set. You need to set a stopping
criteria, based on this reconstruction error as well as the maximum number of iterations. You should play
with several different values for µ and λ to make sure that your final prediction is accurate.
Formatting information is here:
4
Input
• rateMatrix: training data set. Each row represents a user, while each column an item. Observed
values are one of {1, 2, 3, 4, 5}, and missing values are 0.
• lowRank: the number of factors (dimension) of your model. With higher values, you would expect
more accurate prediction.
Output
• U: the user profile matrix of dimension user count × low rank.
• V: the item profile matrix of dimension item count × low rank.
Evaluation [15 pts]
Upload your myRecommender.m implementation file. (Do not copy and paste your code in your report. Be
sure to upload your myRecommender.m file.)
To test your code, try to run homework3.m. You may have noticed that the code prints both training
and test error, in RMSE (Root Mean Squared Error), defined as follows:
X
(u,i)∈M
(Mu,i − f(u, i))2
where f(u, i) is your estimation, and the summation is over the training set or testing set, respectively. For
the grading, we will use another set-aside testing set, which is not released to you. If you observe your test
error is less than 1.00 without cheating (that is, training on the test set), you may expect to see the similar
performance on the unseen test set as well.
Note that we provide homework3.m just to help you evaluate your code easily. You are not expected to
alter or submit this to us. In other words, we will not use this file when we grade your submission. The only
file we take care of is myRecommender3.m.
Grading criteria:
• Your code should output U and V as specified. The dimension should match to the specification.
• We will test your output on another test dataset, which was not provided to you. The test RMSE on
this dataset should be at least 1.05 to get at least partial credit.
• We will measure elapsed time for learning. If your implementation takes longer than 3 minutes for
rank 5, you should definitely try to make your code faster or adjust parameters. Any code running
more than 5 minutes is not eligible for credit.
• Your code should not crash. Any crashing code will be not credited.
Report [10 pts]
In your report, show the performance (RMSE) both on your training set and test set, with varied lowRank.
(The default is set to 1, 3, and 5, but you may want to vary it further.) Discuss what you observe with
varied low rank. Also, briefly discuss how you decided your hyper-parameters (µ, λ).
Note
• Do not print anything in your code (e.g, iteration 1 : err=2.4382) in your final submission.
• Do not alter input and output format of the skeleton file. (E.g, adding a new parameter without
specifying its defalut value) Please make sure that you returned all necessary outputs according to the
given skeleton.
5
• Please do not use additional file. This task is simple enough that you can fit in just one file.
• Submit your code with the best parameters you found. We will grade without modifying your code.
(Applying cross-validation to find best parameters is fine, though you do not required to do.)
• Please be sure that your program finishes within a fixed number of iterations. Always think of a case
where your stopping criteria is not satisfied forever. This can happen anytime depending on the data,
not because your code is incorrect. For this, we recommend setting a maximum number of iteration in
addition to other stopping criteria.
Grand Prize
Similar to the Netflix competition held in 2006 to 2009, the student who achives the lowest RMSE on the
secret test set will earn the Grand Prize. We will give extra 10 bonus points to the winner, and share the
student’s code to everyone. (Note that the winner should satisfy all other grading criteria perfectly, including
answer sanity check and timing requirement. Otherwise, the next student will be considered as the winner.)
Typing Bonus
As usual, we will give 5 bonus points for typed submissions. Note that all questions should be typed to get
this credit.
6

🚀 Custom Work, Just for You! 🚀

Can’t find the tutorial you need? No worries! We create custom, original work at affordable prices! We specialize in Computer Science, Software, Mechanical, and Electrical Engineering, as well as Health Sciences, Statistics, Discrete Math, Social Sciences, Law, and English.

✍️ Custom/Original Work Essays cost as low as $10 per page.
💻 Programming Custom Work starts from $50.

🔥 Get top-quality help now! 🔥

Get Your Custom Work