Machine Learning, Python, Linear Regression, Gradient Descent, Regression Analysis.
steps 3–4: They are repeated until the convergences occur or the stopping criterion is met (tolerance or maximum iterations). Let’s code it in Python: import numpy as np import matplotlib.pyplot as plt def cost_function(X, y, theta): """cost function""" J = np.sum((X.dot(theta) - y)**2)/(2*len(y))