Question: Usin Using R Programming Q1: Suppose now we want to fit a hypothesis (model) y=h(x)=0+1x to the data, where x denotes the size of a

Usin

Using R ProgrammingUsin Using R Programming Q1: Suppose now we want to fit ahypothesis (model) y=h(x)=0+1x to the data, where x denotes the size ofa house and y is the price of the house. You are

Q1: Suppose now we want to fit a hypothesis (model) y=h(x)=0+1x to the data, where x denotes the size of a house and y is the price of the house. You are asked to use gradient descent algorithm to estimate the model parameters 0 and 1. (a) Please explain what a cost function is, and write down the full expression of the cost function for our problem. (5\%) (b) Please explain how gradient descent may make use of the cost function in estimating the model parameters. (5\%) (c) Write (two) R functions that compute the partial derivative of the cost function J(0,1), with respect to 0 and 1 respectively (you may specify the input arguments of the functions to be 0,1,m,x,y, where m is the number of training examples, and x and y are the input and output variables respectively). These functions will facilitate your implementation of the gradient descent algorithm in the next sub-question (Hints: the expression of J() could be found in the handout). (15\%) (d) Write R code to perform gradient descent to estimate 0 and 1, using a threshold 103 to determine convergence (Hints: Use a while loop; mind and specify the choice of the learning rate and also feature scaling). (25\%) You may use this structure or use your own structure (you need to work out "xx" by yourself): \#\# define functions to compute the partial derivative terms dJ0 = function ( theta 0,theta1,m,x,y){ xx \} dJ1= function (theta0, theta1, m,x,y){ xx \} \#\# perform gradient descent \#\# convg_threshold =xx alpha =xx initial_theta0 =xx \# initial guess of theta0 initial_theta1 =xx \# initial guess of theta1 initial_J =xx \# initial value of the cost function

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!