Question: Here is the code to be modify 1. In the lecture, we wrote an R function to apply the batch gradient descent algorithm to fit

 Here is the code to be modify 1. In the lecture,

we wrote an R function to apply the batch gradient descent algorithm

Here is the code to be modify

to fit a linear regression model describing the relationship between the variables

1. In the lecture, we wrote an R function to apply the batch gradient descent algorithm to fit a linear regression model describing the relationship between the variables dist and speed in the cars data. Modify that function to make it implement the stochastic gradient descent algorithm to solve the same probem. Compare the results and computing time for the two algorithms (batch versus stochastic gradient descent). To ensure a fair comparison, make sure to use the same inputs for both algorithms (initial values, learning rate, convergence threshhold, and maximum number of iterations). For these paramters, use the samee inputs we used in the lecture. In your comparison, include the following: a. How close are the estimated coefficients from each method to the coefficients obtained from the built-in im function. system.time({gd. lreg (speed, dist, 0.001, le-10, 1000000) }) gd. lreg max.iter) { converged = TRUE return (cat("Intercept at last iter:", bo, ' ', "Slope at last iter:", bi,' ', "MSE at last iter values:", MSE_new)) #Run the function on the cars data gd.lreg (speed, dist, 0.001, le-10, 1000000) 1. In the lecture, we wrote an R function to apply the batch gradient descent algorithm to fit a linear regression model describing the relationship between the variables dist and speed in the cars data. Modify that function to make it implement the stochastic gradient descent algorithm to solve the same probem. Compare the results and computing time for the two algorithms (batch versus stochastic gradient descent). To ensure a fair comparison, make sure to use the same inputs for both algorithms (initial values, learning rate, convergence threshhold, and maximum number of iterations). For these paramters, use the samee inputs we used in the lecture. In your comparison, include the following: a. How close are the estimated coefficients from each method to the coefficients obtained from the built-in im function. system.time({gd. lreg (speed, dist, 0.001, le-10, 1000000) }) gd. lreg max.iter) { converged = TRUE return (cat("Intercept at last iter:", bo, ' ', "Slope at last iter:", bi,' ', "MSE at last iter values:", MSE_new)) #Run the function on the cars data gd.lreg (speed, dist, 0.001, le-10, 1000000)

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!