Hi @shubhayan it seems that the value of dw in your case is all 0.0. Maybe there is something wrong in the forward/backward prop code in the propagate function ?
@shubhayan I would check the optimize function, in particular the update part of the function. Initially w is al 0. if that’s not changing maybe it is due to the fact that the update rule is not being applied properly.
Maybe you could print w before and after updating it in the optimize function so you can check whether it is being updated or not.
@shubhayan It really looks like a problem inside the optimize function. I passed the assignment and your propagate code above looks identical to mine. I also initially made a mistake while updating my parameters inside the optimize, so need to be careful there.
Secondly, if you have posted the actual code above from the model function, I think optimize should be called with actual arguments like this: optimize(w, b, X_train, Y_train, num_iterations=num_iterations, learning_rate=learning_rate) and not with hardcoded numbers. That could also be an issue. And I think this the issue because in the notebook we can not see the definition of the model_test function. For that you need to go to the hub by clicking File > Open and inspect the public_tests.py file. At around line number 111, the test calls the model function a.k.a target with some specific values for num_iterations, learning_rate parameters. Therefore if you hardcode those parameters inside your model function, your test should run into an anomaly. I think this is happening in this case.
This really mirrors my thoughts, I knew I was doing something wrong with hardcoding numbers into optimize(), when clearly the number of iterations and learning rate is pre-defined in model().
UPDATE: I thought I’d roll with the punches and ended up curiously running logistic_regression_model = model(), and it seems to run[even though model_test(model) is failing]…
Cost after iteration 0: 0.693147
Cost after iteration 100: 0.584508
Cost after iteration 200: 0.466949
Cost after iteration 300: 0.376007
Cost after iteration 400: 0.331463
Cost after iteration 500: 0.303273
Cost after iteration 600: 0.279880
Cost after iteration 700: 0.260042
Cost after iteration 800: 0.242941
Cost after iteration 900: 0.228004
Cost after iteration 1000: 0.214820
Cost after iteration 1100: 0.203078
Cost after iteration 1200: 0.192544
Cost after iteration 1300: 0.183033
Cost after iteration 1400: 0.174399
Cost after iteration 1500: 0.166521
Cost after iteration 1600: 0.159305
Cost after iteration 1700: 0.152667
Cost after iteration 1800: 0.146542
Cost after iteration 1900: 0.140872
train accuracy: 65.55023923444976 %
test accuracy: 34.0 %
@shubhayan what’s the current error log now? Did you remove the hardcoded numbers when calling the optimize function as suggested by @chandan1986.sarkar? The function should be called with the input parameters to the function model and not any specific values.
Does the d['w'] value match with your print outs of w? I mean, your output value [[0.] [0.] [0.] [0.]] appears in the print out when you execute your code with the model_test function?
After calling the optimize function in model there is an statement to update w and b, could you try printing out w before and after that statement. If w is all zeros it looks like this variable is not being updated because it is initialized with zeros.
On further analysis, it appears there is an issue in the test file “public_tests.py”.
It is missing “print_cost=True” as a last parameter in the below call: -
d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=1e-4)
After modifying this line in the test file to: -
d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=1e-4, print_cost=True)
I get the below results on executing “model_test(model)”: -
Cost after iteration 0: 0.693147
train accuracy: 66.66666666666667 %
test accuracy: 66.66666666666667 %
All tests passed!
Subsequent call to logistic_regression_model = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.005, print_cost=True) gives me the same results as above post.
Overall, I think the issue is resolved but on submission of the assignment it still shows as failed.
Please check and let me know if something needs to be done at my end. Thanks!
I would think so too to refrain from changing the test file. But in this case, the issue seems to be from a function call with inadequate parameters when the function expects it. The model function is just a consolidation of calls to all previous functions that have run correctly.