Week 2 Programming Assignment (Deep Learning)

(First programming assignment in course)
I’m getting this error, seems to be that the test made is wanting to get a costs list of length 1 while there is 2000 iterations passed into the optimize function causing 20 appends to the costs list, therefore I’m getting length 20. Is there a mistake in the values I’m defining?

Solved by not using any hard coding in the call to the optimize function, just used the names of the variables. Hope this solves the problem for someone else as well. Best of luck to everyone out there. Enjoy!

Glad you were able to figure this out, Jacob, and thank you for sharing your solution as well!

Hello Mubsi, thank you for your help in advance. Just curious what’s the difference between using names of the variables only and define num_iterations, learning_rate when call optimize() in this code, aka:
working: params, grads, costs = optimize(w, b, X_train, Y_train,num_iterations, learning_rate, print_cost).
failed: params, grads, costs = optimize(w, b, X_train, Y_train,num_iterations=100, learning_rate=0.09, print_cost=False)

Also not sure in this example, are we using learning_rate=0.09 in optimize() or learning_rate=0.5 in model() to calculate out value for “w”?

The difference is: if you hard-code like num_iterations=100, your code will work only for 100 iterations. And, if you do num_iterations=num_iterations or just num_iterations, it will work for whatever value you give it when calling a function. Our test cases used different values, so hard-coding failed the test.

1 Like

Got it and thanks a lot Saif!