WK#2 final code assignment-code passed tests but I keep getting errors with Model function

I think I have them all… grads, cost = propagate(w, b, X, Y), I also removed everything marked in pink. new error ypeError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
123 y_test = np.array([[0, 1, 0]])
124
→ 125 d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=0.01)
126
127 assert type(d[‘costs’]) == list, f"Wrong type for d[‘costs’]. {type(d[‘costs’])} != list"

in model(X_train, Y_train, X_test, Y_test, num_iterations, learning_rate, print_cost)
36 # YOUR CODE STARTS HERE
37 w, b = initialize_with_zeros(X_train.shape[0])
—> 38 params, grads, costs = optimize(num_iterations, learning_rate, print_cost)
39 Y_prediction_test = predict(w, b, X_test)
40 Y_prediction_train = predict(w, b, X_train)

TypeError: optimize() missing 1 required positional argument: ‘Y’

I recommend you look at the function definition for optimize() - it is the first line in the cell that has the function - and look at the order of the arguments.

That’s not what I said to do.

Fair enough. I’m honestly confused at what your suggesting I should do.

Here is the function definition for optimize():

Observe that it has seven parameters. I have marked them in the image.

Compare this to your code in model(), and what variables you are using when you call optimize().

Fix any discrepancies.

Still confused… I can only give 4 positional arguments in exercise 6 so how do I fit 7 arguments into 4?

TypeError Traceback (most recent call last)
in
----> 1 params, grads, costs = optimize(w, b, X, Y, num_iterations=100, learning_rate=0.009, print_cost=False)
2
3 print ("w = " + str(params[“w”]))
4 print ("b = " + str(params[“b”]))
5 print ("dw = " + str(grads[“dw”]))

in optimize(w, b, X, Y, num_iterations, learning_rate, print_cost)
35 # grads, cost = …
36 # YOUR CODE STARTS HERE
—> 37 grads, cost = propagate(w, b, X, Y, num_iterations, learning_rate, print_cost)
38
39 # YOUR CODE ENDS HERE

TypeError: propagate() takes 4 positional arguments but 7 were given

So, you are working on Ex. 6: optimize.
You can see from Ex. 5 that propagate function can take only 4 arguments. So, you have to pass only 4 arguments.
Previously, you shared an error from Ex. 8 where you have to call the optimize function which can take 7 arguments, and that is what Tom mentioned.

So in Ex. 6 I have propagate written now with only four arguments (w, b, X, Y)
and in Ex. 8 I have optimize written with seven positional arguments as written above. But I still get an assertion error regarding w.

Please share that assertion with us. But before proceeding to the next Ex., make sure you passed all the previous ones.

AssertionError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
132 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
→ 133 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
134
135 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"

AssertionError: Wrong values for d[‘w’]. [[0.]
[0.]
[0.]
[0.]] != [[ 0.08639757]
[-0.08231268]
[-0.11798927]
[ 0.12866053]]

All tests passed previous to running Ex.8

It looks like you are making some version of the mistake described on this post earlier in this same thread.

1 Like

I am, and I have read through all 10,000 threads regarding the topic. I just don’t understand how to access the true parameters versus the default parameters. I’m also not sure that I haven’t committed a hardcode error.

To access the default value of the model function to the optimize function, you just don’t pass that argument to the optimize function. And if you pass like learning_rate = 0.1, this is hard coding.
So, you don’t have to pass default and hard-coded.

1 Like

Understood, so I removed any numerical value associated with the keyword arguments. The error still persists,

I think I am not extracting the returned values from the dictionary, after the call to initialize_with_zeros, and I’m not sure how I would precede in doing so.

Let’s say, to get x from a dictionary named diction, you can do this like diction['x'].

1 Like

Right, and then assign it to the variable name you want.

1 Like

I give up

Did you read the template code that they gave you which creates the return values from the function?

But the higher level conclusion here is that the best course of action might be to put this course on hold and go take an “intro to python” course first. This course assumes you already know python.

1 Like