W4_A2_backpropogation_Train_x_not_defined

I’m getting NameError: name 'train_x' is not defined after completing the L_layer_model function and running:

parameters, costs = L_layer_model(train_x, train_y, layers_dims, num_iterations = 1, print_cost = False)

print("Cost after first iteration: " + str(costs[0]))

L_layer_model_test(L_layer_model)

Everything else runs just fine and passes until this point…
I have not changed or touched the x_train variable.

Tried rebooting the lab but does not work…
Last change to the lab was Jun 20, 2023

How do I start debugging this?

Have you run all the above cells? If so, please share your full error.

I’ve run all the cell.

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-d5e7eb27c0fc> in <module>
----> 1 parameters, costs = L_layer_model(train_x, train_y, layers_dims, num_iterations = 1, print_cost = False)
      2 
      3 print("Cost after first iteration: " + str(costs[0]))
      4 
      5 L_layer_model_test(L

And then the error I mentioned

Please share the full error, not just it’s part. Maybe screenshot.


that little [2] in your screen capture is an execution count. It suggests that only 1 cell above this one has been executed in this session, which is consistent with the NameError you are getting. When @saifkhanengr asks if you have ‘run all the above cells’ he meant also ‘in this session.’ It is not enough that you ran it once before…context is lost each time the kernel restarts.

If you restart the kernel and select ‘Run all’ do you see this error?

Run all the cells, from the start in cell 2 train_x_orig is defined and train_x is the modified version defined in cell 5. Try running all the cells. It may help.

I was on the go so have sent what I had from mobile.
As mentioned, I ran all cells already with same problem and also rebooted the lab:

Was too quick to post the screenshot - I see the error is for another variable now. Though I have not touched it as well…
Wait - I have a typo. Running again.
And now it runs.

I wonder why I was getting an error for another variable.
But I can live with it :slight_smile:
Thanks for all the answers