









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










- It is an algorithm to minimize a cost function by
plt.scatter(x, y, color='red') k = 100 # Plot every kth line for i in range(0, iterations+1, k): m_curr_k = m_curr - i/k * md c_curr_k = c_curr - i/k * cd y_predicted_k = m_curr_k * x + c_curr_k plt.plot(x, y_predicted_k, color='blue') plt.title('Line of Best Fit') plt.xlabel('x') plt.ylabel('y')
x_mean = np.mean(x) y_mean = np.mean(y) slope, intercept = np.polyfit(x, y, 1) plt.plot(x_mean, y_mean, marker='o', markersize=5, color="green") plt.plot(x, slope*x + intercept, color='green') plt.show() x = np.array([1, 2, 3, 4, 5]) y = np.array([5, 7, 9, 11, 13]) gradient_descent(x, y)