Week 2 _Final Assignment _ Merge All functions in the Model

Can some one please help me with this, I am stuck here---->

GRADED FUNCTION: model

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):
# mentor edit: code removed

I get an error →
in predict(w, b, X)
16 m = X.shape[1]
17 Y_prediction = np.zeros((1, m))
—> 18 w = w.reshape(X.shape[0], 1)
19
20 # Compute vector “A” predicting the probabilities of a cat being present in the picture

ValueError: cannot reshape array of size 2 into shape (4,1)

Hi @sufiyan.saqib, I would check the shape of w prior the reshape operation:

print(w.shape)
print(w)

Check if the above outputs are consistent with what you would expect for w.

Note that if you’ve pasted your actual code it is incomplete, for example, you haven’t initialized w and b.

The mistake i was doing was using :-
w = params[“w”]
b = params[“b”]

Where as :-
w = parameters[“w”]
b = parameters[“b”], was supposed to be used. This was giving me the shape error

Hi ! have you seen this error message before?

TypeError 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)
37 w,b = initialize_with_zeros(X_train.shape[0])
38 params, grads, costs = optimize(w, b, X_train,Y_train, num_iterations, learning_rate, print_cost)
—> 39 w=params[w]
40 b=params[b]
41 Y_prediction_test = predict(w, b, X_test)

TypeError: unhashable type: ‘numpy.ndarray’

The error comes from these two lines. You should use w and b as a string. Using double quotes (") or single quotes (') will help.

1 Like

Yes! I didn’t use a string on the dic, figure it out shortly after, thank you for taking the time to review the error message !