Perform gradient descent to learn theta by minimizing the cost function