Question: 1) (10 pts) Given a dataset with three one-dimensional instances {([1],4),([2],2),([4],1)} (e.g., the feature vector and ground-truth label of the first instance is [1] and

 1) (10 pts) Given a dataset with three one-dimensional instances {([1],4),([2],2),([4],1)}

(e.g., the feature vector and ground-truth label of the first instance is

1) (10 pts) Given a dataset with three one-dimensional instances {([1],4),([2],2),([4],1)} (e.g., the feature vector and ground-truth label of the first instance is [1] and 4, respectively). Suppose we use a linear predictor f=wx+w0 to fit the data (w0 is called the offset), with squared loss as the loss function. Complete the codes in "hw1_gradientDescent.py" to solve w and w0 using gradient descent. Report in "YourID_HW1.pdf": (1) the codes you write to fulfill the functionality; (2) the outputs at iteration 0,1990 and 2000. hw1_gradientDescent.py >dF 1 import numpy as np 2 import math 3 "I" 4 TODO: Complete the three lines of codes below. And run the program to get the result. NOTE: ***Don't change other parts of this program. *** "n" \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Data and Modeling: what we want to compute points =[(np.array([1]),4),(np.array([2]),2),(nparray([4]),1)] d=1 \# Function def F(w,w_) : \# 1. Implement the loss function below. return \# Gradient of the function above w.r.t. w and w_. def dF(w2,w) : \# 2. Implement the computation of gradient below for the loss function, with respect to w and w_ . return \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Algorithms: how we compute it def gradientDescent (F,dF,d) : w,w=npzeros(d),. eta =0.02 for t in range(2001): value =F(w,w) gradient_w, gradient_w_ =dF(w,w) w=w - eta gradient_w \# 3. Implement the update of w using gradient descent. w= if t%10==0: print( 'iteration \{\}:w={},w={},F(w,w)={} '.format (t,w,w, value ) ) gradientDescent (F,dF,d)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!