C2W4 Assignment gradient_descent

Hello. When testing the last gradient_descent function, I found my returning values like this:
Call gradient_descent
iters: 10 cost: 10.868077
iters: 20 cost: 12.380256
iters: 30 cost: 27.418218
iters: 40 cost: 66.061808
iters: 50 cost: 163.440260
iters: 60 cost: 544.461516
iters: 70 cost: nan
it blew up and became nan after 70. Why would it be this case?

1 Like

Dear @mejiroalbon,

Welcome to the Community!

Your gradient descent is diverging – likely due to a learning rate that’s too high, causing cost to grow until it overflows to NaN. Lower the learning rate to fix it.


Keep Learning AI with DeepLearning.AI - Girijesh

hi @mejiroalbon

can confirm if you passed previous unittest with expected output??

if yes then check how you calculated cost in gradient descent code. remember initial iteration has been already recalled as iters = 0, so use this correctly to implement the iterations with batch_size told to use 128 (I am providing you indirect hints). if your updated gradient weights and biases are implemented incorrect that could also add issue to your exploding gradient.

Thank you for your suggestion. It do helped to control this situation.

1 Like

Hi. The previous tests were all passed and the problem only occured in the last function. However thanks for your advice.

1 Like

your issue is resolved?