Week 2 Programming Assignment Logistic Regression with a Neural Network Mindset

I don’t know why I am getting this error?? Can someone tell me about this??

Okay, Even i have written num_iterations = 2000, what should i write instead?
Thank you for help.

@Mohit21091 num_iterations is an input to the model function, therefore there is no need to hardcode the value, you can just all the function with num_iterations as defined in the signature of the model function. See below an example with an unrelated set of functions, as you can see inside model there is no need to hardcode the value as the function will take whatever is defined in the input_value parameter.

def test_function(input_value = 50):
    ...

def model (input_value = 100):
   ...
   test_function(input_value)

input_value = 80
model(input_value)
2 Likes

Thank you very much !

I went to compile the imports at the start of the assignment, but it gave me an error. Should this first section run without an error? Or is that part of what we have to do?

@sagetea: The import cell does not require you to change anything: it should “just work”. Please show us the actual error you are getting. My first suggestion is to do “Kernel → Restart and Clear Output” and then run that cell again.

Update: I just checked and that cell is modifiable. So another possibility is that you accidentally modified it in a damaging way. E.g. hit “Enter” instead of “Shift-Enter” while your cursor was in that cell. There is a topic on the FAQ Thread about how to get a clean copy of the notebook to recover it if damage to the cell is a possibility.

Hello Paul,
I did as you said and clicked the Help Button at the top right. I reloaded the notebook. I then did Shift Enter and unfortunately still see the same error. By the way, Enter just adds a new line. Something is not right here. I am having trouble making progress as I am still stuck on this first step. Please assist…thanks,
David

Here is the error that I am getting. ---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
in
7 from scipy import ndimage
8 from lr_utils import load_dataset
----> 9 from public_tests import *
10
11 get_ipython().run_line_magic(‘matplotlib’, ‘inline’)

~/work/release/W2A2/public_tests.py in
1 import numpy as np
----> 2 from test_utils import single_test, multiple_test
3
4
5 def sigmoid_test(target):

ModuleNotFoundError: No module named ‘test_utils’

Try clicking “File → Open” from the notebook and looking at the files that are there in the file navigation view. There should be a file called test_utils.py. If not, doing the “Lab Help → Get Latest Version” should fix that. That operation replaces any missing files.

Yes, hitting “Enter” just creates a new line, but what if your cursor was positioned in the middle of a line? Then you’d be splitting the line into two pieces, right? That could have bad effects, no?

Also note that doing the “Get Latest Version” will only give you a fresh notebook if you renamed yours out of the way. If you don’t, then it’s a NOOP, right? The instructions are pretty clear on that point.

Ah hah. So I had a look and the test_utils.py file was in a folder called W2A1. I downloaded that, and then uploaded to W2A2, and then Ctrl-Enter worked.
Thanks for that!

The problems that will face you in this exercise is not making the variables in optimize function using numbers just use it as the names of the variables in the input arguments.
After making this all the tests will be success.
optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)

Hi, I have read all your posts here. You repeatedly used the word “hardcode”, but would you please explain? I guessed it was to remove “=2000” for the parameter num_iterations, however it does not change anything.

Thank you for your time.

1 Like

Well, that may not have been your only bug. Generally speaking, it is a mistake to have an equal sign assignment in a parameter unless it is the definition of the function (in which case you are declaring the default value of an optional parameter) or in the actual top level invocation of a function (as in the test case that invokes the function).

One way to debug this is to show us the exception trace or error that you are seeing.

I guess there should be a bracket before “/m” in db line.
db=(np.sum((A-Y)))/m , because of which there is a syntax error in the next line of code.

1 Like

I guess in line 32, you will have to transpose in two places,
np.log(A).T… and np.log(1-A).T) … This worked for me!.

1 Like

Hi @Retainer_No.501, what I mean with hardcoding is to fix the value of a parameter in a function without taking into account the inputs. An this can be seen easily with an example:

# The function_a takes a parameter called my_parameter
# whose default value is my_parameter i.e. if no input
# is passed to the function then my_parameter would have
# the value of 100
def function_a(my_parameter=100):
    print(my_parameter)

# Function b just prints something and calls the function_a
# Both function_a and function_b have no hardcoded parameters
def function_b(my_parameter):
    print("This is a test")
    function_a(my_parameter)


# A hardcoded example would be implementing the function_b
# as follows. In function_b we are ignoring the value passed
# as input my_parameter and we have hardcoded 50 as input.
def function_b(my_parameter):
    print("This a test")
    function_a(50)

So in general, you have to passed on the parameters every function is receiving and use them. Do not fix values for variables / parameters which are inputs to the functions.

1 Like

Hi there,

I have been trying to get this working for several days now, and downloaded a new notebook after naming the old one. All tests are passed until exercise 8 - model. I am getting a syntax error in the ‘w =’ line as follows:
model_invalid_syntax

The preceding line is the params, grads, costs line and the values for num_iterations, learning_rate are definitely not hardcoded (I downloaded the new notebook to make 100% sure that I had everything exactly as it would be when fresh, but the line itself is clearly not hardcoded) .

Please advise

apologies: ‘naming’ = ‘renaming’

I eventually solved the syntax error. I am now getting:
‘AttributeError: ‘tuple’ object has no attribute ‘T’’ and it is pointing at ‘propagate’. There are transpose functions there, but the unit test was passed.

Is the error in ‘model’?

Dear Peter,

I am not able to understand why you are putting an extra zero as a value
while running the codes for w,b. I think that extra zero is throwing an
error in your output. Please rewrite the code again for w,b and check
whether it’s working or not?

Thanks!