C1_W3_Logistic_Regression, section 2.4, NameError name 'X' not defined

Requesting help in C1_W3_Logistic_Regression, section 2.4 ”2.4 Cost function for logistic regression” under #UNQ_C2. For the lab supplied code, I keep getting the following error even after successfully running all code listed under section 1 (Packages) and Section 2 (Logistic Regression) and closing/reloading the lab:

NameError: name 'X' is not defined

This is confusing because this code supplied by the lab itself (not mine) and I’ve not edited it.

Suggestions?

Thanks!

-Scott

FYI - I solved the problem. Root cause was lack of indentation.

Please see ‘fix’ below where line 16 is now indented where it wasn’t before. The indentation serves to include the variable assignment into the compute_cost function where X is defined. Indenting line 16 put the assignment outside the function, which is why X was undefined.

4 Likes