def gradientDescent (X, y, theta, alpha, num_iters): This function returns a tup
ID: 3750995 • Letter: D
Question
def gradientDescent (X, y, theta, alpha, num_iters): This function returns a tuple (theta, cost_array) m len(y) cost array - for i in range(0, num_iters): START TODO # Make predictions # Hint: y.hat = theta-0 + (theta-1 * x_1 ) + (theta-2 * x-2) # Shape of y-hat: m by 1 Y_hat- # Compute the difference between predictions and true values # Shape of residuals: m by 1 residuals y_hat-y # Calculate the current cost cost = cost_array.append(cost) # Compute gradients # Shape of gradients: 3 by 1, i.e., same as theta gradients # Update theta theta return theta, cost_arrayExplanation / Answer
import numpy
y_hat = theta_0 + theta_1 * X
cost = ((X*theta-y) * X') / m
gradients = numpy.gradient(3,1)
theta = theta - alpha * cost
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.