Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 house

Using R Programmingimage text in transcribed

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions