Queries regarding W4 last assignment - Deep Neural Network - Application

I’ve passed the assignment with 100/100 points, though I’m not getting same result as the expected ones for cost and accuracy of L layer NN. I believe the code I used in the for loop is correct which basically is:

{moderator edit - solution code removed}

Though I’m getting cost=0.6950464961800915 for 1st iteration while the expected output showing in the assignment is 0.77; Meanwhile my accuracy for L NN only arrives at 74% while the expected result should be 80%. Not sure what I did wrong earlier or why I am seeing the different result here?

In additional, when trying to figure above out, I tried to change the last parameters line to:
parameters = update_parameters(parameters, grads, learning_rate = 0.0075), then it’s giving me an error stating wrong output for W and b values. Just curious if I am not hard coding learning_rate to 0.0075, what learning rate this function is using. Why it’s not using 0.0075 since the value was defined at the beginning:
def L_layer_model(X, Y, layers_dims, learning_rate = 0.0075, num_iterations = 3000, print_cost=False)

1 Like

Dear @HuiminShi,

Please send me the code via direct message.
You can do this by clicking on my name and then click Message.
Kindly note that sharing code in the community is against the code of conduct, so please do not post it here.


Keep Learning AI with DeepLearning.AI - Girijesh

I think you are misinterpreting the meaning of that statement. You should google “python named parameters” and read up on how they work. The fact that it says:

learning_rate = 0.0075

in the definition of that function does not mean that the value is hard-coded to 0.0075. What it means is that parameter is optional. If you call the function and do not supply a value for learning_rate, then 0.0075 will be used. It would not be a good idea to hard-code the parameter on the call to update_parameters: you should just use whatever value is passed to the top level function. Even if they are using the default value in the notebook test cases, you can’t assume that the grader will also do that.

I’m surprised that you can pass the grader with 100% when you have this discrepancy in results. Are you sure that the version you submitted to the grader is the same as the one that gives those different results?

2 Likes

One other question: did you manually import your subroutines from the previous W4 Step by Step assignment? That would be a mistake and will give you different results but that method will definitely not pass the grader. They gave you imported versions of those “worker” functions from the previous assignment and the initialization function they gave for the “deep” case is different than what we build in the previous assignment.

1 Like

Ok, I went back and did some experiments and I’ll bet what you did was just run the training for the L layer model without running the cell that sets:

### CONSTANTS ###
layers_dims = [12288, 20, 7, 5, 1] #  4-layer model

So you trained the L layer model code, but with the two layer architecture:

layers_dims = (12288, 7, 1)

So your code is actually correct, but you ran it with the wrong parameters. But the wrong parameter wasn’t learning_rate. :nerd_face:

3 Likes

Thank you so much Paul! You are correct and I went back to re-run the code, made sure I was using L layer test input this time and the result shows exactly as the expected ones now. :+1:

2 Likes

Thanks a lot Girijesh, Paul has addressed what I did wrong earlier below and the issue has been figured out now.

1 Like