Problem in Week 3 programming assignment - predict didn't defined in previous cells

I’ve passed all tests in programming assignment week3. But in executing cell below has a problem. Because ((predict)) didn’t defined in previous cells.

Test your predict code

np.random.seed(1)
tmp_w = np.random.randn(2)
tmp_b = 0.3
tmp_X = np.random.randn(4, 2) - 0.5

tmp_p = predict(tmp_X, tmp_w, tmp_b)
print(f’Output of predict: shape {tmp_p.shape}, value {tmp_p}')

UNIT TESTS

predict_test(predict)

NameError Traceback (most recent call last)
in
5 tmp_X = np.random.randn(4, 2) - 0.5
6
----> 7 tmp_p = predict(tmp_X, tmp_w, tmp_b)
8 print(f’Output of predict: shape {tmp_p.shape}, value {tmp_p}')
9

NameError: name ‘predict’ is not defined

1 Like

You probably have not defined the predict method or function!

Yes, it isn’t defined but in the programming assignment, I can’t change the codes.

Maybe you didn’t run the defined function before using it.
After finishing the predict function, try to press “shift+return” to run the predict function so that you can use it in the later code, otherwise it would show that this function is not defined.

Hello @Shokoofeh_Khani,

We lock ungraded cells in all assignment. If you wonder how to handle error that appears in a locked ungraded code cell, you may want to take a look at this FAQ.

As for the problem you are encountering, as @gent.spah and @YijinChen suggested, since predict is your exercise 4, you need to first run the code cell containing it in order to define it, before running any subsequent code cell. Also, each time you re-open a notebook, please make sure to run all the code cells from the top.

Cheers,
Raymond

Every time you open a notebook, you must run all of the cells in the notebook starting from the top.