why gradient descent when we can solve linear regression analytically

John picture John · Aug 12, 2013 · Viewed 25.5k times · Source

what is the benefit of using Gradient Descent in the linear regression space? looks like the we can solve the problem (finding theta0-n that minimum the cost func) with analytical method so why we still want to use gradient descent to do the same thing? thanks

Answer

jabaldonedo picture jabaldonedo · Aug 12, 2013

When you use the normal equations for solving the cost function analytically you have to compute:

enter image description here

Where X is your matrix of input observations and y your output vector. The problem with this operation is the time complexity of calculating the inverse of a nxn matrix which is O(n^3) and as n increases it can take a very long time to finish.

When n is low (n < 1000 or n < 10000) you can think of normal equations as the better option for calculation theta, however for greater values Gradient Descent is much more faster, so the only reason is the time :)