W4 A1 | Local variable referenced before assignment

I am struck with this for about an hour and i still can’t spot my error. Any help will be appreciated


This kind of error means that the variable that you named linear_cache is not defined yet at the position that it is executed by the Python interpreter.

Maybe you declared it with another name? or another possibility is that you did not execute a cell where you defined it.

I have defined the same variable in an earlier module as well as executed the cell too but still it does not seem to work

The problem is that you are passing an incorrect value for the “activation” parameter to linear_activation_forward and, as a result, it does not match either of the possible choices. You are passing an object reference to the function in question. The lower level function you are calling expects the string name of the function. In other words, relu is not the same thing as “relu”. The former is an object reference to the function. The latter is the string name of the function.

Thank you so much. It helped

Hello, I have a similar issue with error message :

I have checked my earlier functions but I really can’t find out what the problem is :frowning:
thank you very much in advance for your help

Welcome to the community.

If you look at parameters that you passed to linear_activation_forward() for activation, those are not “String”. For example relu is a local variable, and is not a string unless you inserted a string "relu" in a variable relu. And, Paul described exactly samething. So, you already have the answer in here.

linear_activation_forward() only takes "relu" and "sigmoid" as a string value for activations. If parameter passed is not any of those, then, no further calculation is processed. Then, there may be some unassigned variable exist.

Right. As Nobu describes, this is exactly the same error that was explained earlier in this thread.