Erba Aitbayev
Erba Aitbayev

Reputation: 4353

How to check if gradient descent with multiple variables converged correctly?

In linear regression with 1 variable I can clearly see on plot prediction line and I can see if it properly fits the training data. I just create a plot with 1 variable and output and construct prediction line based on found values of Theta 0 and Theta 1. So, it looks like this:
enter image description here


But how can I check validity of gradient descent results implemented on multiple variables/features. For example, if number of features is 4 or 5. How to check if it works correctly and found values of all thetas are valid? Do I have to rely only on cost function plotted against number of iterations carried out?

Upvotes: 4

Views: 1860

Answers (3)

aasharma90
aasharma90

Reputation: 41

There are some things you can try.

1) Check if your cost/energy function is not improving as your iteration progresses. Use something like "abs(E_after - E_before) < 0.00001*E_before", i.e. check if the relative difference is very low.

2) Check if your variables have stopped changing. You can opt a very similar strategy like above to check this.

There is actually no perfect way to fully make sure that your function has converged, but some of the things mentioned above are what usually people try.

Good luck!

Upvotes: 0

alexeykuzmin0
alexeykuzmin0

Reputation: 6440

We can think of gradient descent as of something solving a problem of f'(x) = 0 where f' denotes gradient of f. For checking this problem convergence, as far as I know, the standard approach is to calculate discrepancy on each iteration and see if it converges to 0.
That is, check if ||f'(x)|| (or its square) converges to 0.

Upvotes: 0

Don Reba
Don Reba

Reputation: 14051

Gradient descent converges to a local minimum, meaning that the first derivative should be zero and the second non-positive. Checking these two matrices will tell you if the algorithm has converged.

Upvotes: 3

Related Questions