Exercise 1 is an error grading

I am working at Exercise 1 and finish it but then I find the blue button on the right corner of Jupiter NB page and submit my assigment1 3 times. The result is bellow you are graded Exercise 2

[ValidateApp | INFO] Validating ‘/home/jovyan/work/submitted/courseraLearner/W2A1/Python_Basics_with_Numpy.ipynb’
[ValidateApp | INFO] Executing notebook with kernel: python3
Tests failed on 8 cell(s)! These tests could be hidden. Please check your submission.

The following cell failed:

print("basic_sigmoid(1) = " + str(basic_sigmoid(1)))

basic_sigmoid_test(basic_sigmoid)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-41d37f82dbf3> in <module>
----> 1 print("basic_sigmoid(1) = " + str(basic_sigmoid(1)))
      2 
      3 basic_sigmoid_test(basic_sigmoid)

<ipython-input-3-a5e48d617d04> in basic_sigmoid(x)
     21     # YOUR CODE ENDS HERE
     22 
---> 23     return s

NameError: name 's' is not defined

==========================================================================================
The following cell failed:

t_x = np.array([1, 2, 3])
print("sigmoid(t_x) = " + str(sigmoid(t_x)))

sigmoid_test(sigmoid)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-51251e2b44ae> in <module>
      1 t_x = np.array([1, 2, 3])
----> 2 print("sigmoid(t_x) = " + str(sigmoid(t_x)))
      3 
      4 sigmoid_test(sigmoid)

<ipython-input-8-124fd7e0f21e> in sigmoid(x)
     19     # YOUR CODE ENDS HERE
     20 
---> 21     return s

NameError: name 's' is not defined

==========================================================================================
The following cell failed:

t_x = np.array([1, 2, 3])
print ("sigmoid_derivative(t_x) = " + str(sigmoid_derivative(t_x)))

sigmoid_derivative_test(sigmoid_derivative)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-fa7ab0e756fc> in <module>
      1 t_x = np.array([1, 2, 3])
----> 2 print ("sigmoid_derivative(t_x) = " + str(sigmoid_derivative(t_x)))
      3 
      4 sigmoid_derivative_test(sigmoid_derivative)

<ipython-input-10-0f41f9ee8008> in sigmoid_derivative(x)
     21     # YOUR CODE ENDS HERE
     22 
---> 23     return ds

NameError: name 'ds' is not defined

==========================================================================================
The following cell failed:

# This is a 3 by 3 by 2 array, typically images will be (num_px_x, num_px_y,3) wher...
t_image = np.array([[[ 0.67826139,  0.29380381],
                     [ 0.90714982,  0.52835647],
                     [ 0.4215251 ,  0.45017551]],

                   [[ 0.92814219,  0.96677647],
                    [ 0.85304703,  0.52351845],
                    [ 0.19981397,  0.27417313]],

                   [[ 0.60659855,  0.00533165],
                    [ 0.10820313,  0.49978937],
                    [ 0.34144279,  0.94630077]]])

print ("image2vector(image) = " + str(image2vector(t_image)))

image2vector_test(image2vector)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-13-333007a11e42> in <module>
     12                     [ 0.34144279,  0.94630077]]])
     13 
---> 14 print ("image2vector(image) = " + str(image2vector(t_image)))
     15 
     16 image2vector_test(image2vector)

<ipython-input-12-aeadfa128596> in image2vector(image)
     17     # YOUR CODE ENDS HERE
     18 
---> 19     return v

NameError: name 'v' is not defined

==========================================================================================
The following cell failed:

x = np.array([[0, 3, 4],
              [1, 6, 4]])
print("normalizeRows(x) = " + str(normalize_rows(x)))

normalizeRows_test(normalize_rows)

The error was:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-15-7c7c8401963e> in <module>
      3 print("normalizeRows(x) = " + str(normalize_rows(x)))
      4 
----> 5 normalizeRows_test(normalize_rows)

~/work/submitted/courseraLearner/W2A1/public_tests.py in normalizeRows_test(target)
    162     ]
    163 
--> 164     test(test_cases, target)
    165 
    166 def softmax_test(target):

~/work/submitted/courseraLearner/W2A1/test_utils.py in test(test_cases, target)
     24         print('\033[92m', success," Tests passed")
     25         print('\033[91m', len(test_cases) - success, " Tests failed")
---> 26         raise AssertionError("Not all tests were passed for {}. Check your ...

AssertionError: Not all tests were passed for normalize_rows. Check your equations ...

==========================================================================================
The following cell failed:

t_x = np.array([[9, 2, 5, 0, 0],
                [7, 5, 0, 0 ,0]])
print("softmax(x) = " + str(softmax(t_x)))

softmax_test(softmax)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-589a35b2026d> in <module>
      1 t_x = np.array([[9, 2, 5, 0, 0],
      2                 [7, 5, 0, 0 ,0]])
----> 3 print("softmax(x) = " + str(softmax(t_x)))
      4 
      5 softmax_test(softmax)

<ipython-input-16-96ffcfc4e14a> in softmax(x)
     28     # YOUR CODE ENDS HERE
     29 
---> 30     return s

NameError: name 's' is not defined

==========================================================================================
The following cell failed:

yhat = np.array([.9, 0.2, 0.1, .4, .9])
y = np.array([1, 0, 0, 1, 1])
print("L1 = " + str(L1(yhat, y)))

L1_test(L1)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-21-3f77e39d7fb5> in <module>
      1 yhat = np.array([.9, 0.2, 0.1, .4, .9])
      2 y = np.array([1, 0, 0, 1, 1])
----> 3 print("L1 = " + str(L1(yhat, y)))
      4 
      5 L1_test(L1)

<ipython-input-20-d6f9496ada2a> in L1(yhat, y)
     18     # YOUR CODE ENDS HERE
     19 
---> 20     return loss

NameError: name 'loss' is not defined

==========================================================================================
The following cell failed:

yhat = np.array([.9, 0.2, 0.1, .4, .9])
y = np.array([1, 0, 0, 1, 1])

print("L2 = " + str(L2(yhat, y)))

L2_test(L2)

The error was:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-23-8bbdf5303d2e> in <module>
      2 y = np.array([1, 0, 0, 1, 1])
      3 
----> 4 print("L2 = " + str(L2(yhat, y)))
      5 
      6 L2_test(L2)

<ipython-input-22-2adae5a1fa44> in L2(yhat, y)
     18     # YOUR CODE ENDS HERE
     19 
---> 20     return loss

NameError: name 'loss' is not defined

What must I do to solving this problem ?

1 Like

It sounds like you have not actually filled in the code that you need to write in the bodies of the various functions. E.g. in basic_sigmoid, there needs to be a line of code like:

s = … formula for sigmoid with x as the input value …

Are you sure you filled that in? How much experience do you have programming python? Note that this course is not a beginning programming course. It assumes you are reasonably competent at using python.

1 Like

Hi, I had not trouble with assignment 1 until I encountered L2. The answers seems a simple use of np.dot(…,…)
but returns this error, suggesting the test function does not exist:
NameError Traceback (most recent call last)
in
4 print("L2 = " + str(L2(yhat, y)))
5
----> 6 L2_test(L2)

NameError: name ‘L2_test’ is not defined

Do I need to log out and log back on.

Thanks, PaoloAntonio

1 Like

No, it essentially means the opposite of that: the problem is that you have not re-established the “runtime” memory image of the notebook since the last time you opened it. You need to run the previous cells to define all the functions that you need. Try “Cell → Run All Above” and then this error should go away.

BTW there is a topic about that on the FAQ Thread, which is worth a look for other reasons as well if you are just starting the course.

1 Like