W2_ValueError_Model_Test(target)_ValueError: shapes (1,4) and (2,3) not aligned

Hi, i’m getting this error in the week 2 model part , please help me understand the error

ValueError 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 w, b= initialize_with_zeros(X_train.shape[0])
37
—> 38 params, grads, costs = optimize(w, b, X, Y, num_iterations, learning_rate, print_cost)
39 w = params[w]
40 b = params[b]

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

in propagate(w, b, X, Y)
30 # cost = …
31 # YOUR CODE STARTS HERE
—> 32 A = sigmoid(np.dot(w.T,X) + b)
33 cost = (-1/m)*np.sum(np.dot(np.log(A),Y.T)+np.dot(np.log(1-A),(1-Y).T))
34

<array_function internals> in dot(*args, **kwargs)

ValueError: shapes (1,4) and (2,3) not aligned: 4 (dim 1) != 2 (dim 0)

Hello @SivaramaKrishnan!

Double check the implementation of cost in Exercise 5 - propagate. You are transposing the wrong term.

Best,
Saif.

1 Like

The propagate code looks ok (different than how I wrote it but should work), but the problem is you are referencing the global variables X and Y when you call optimize from model. Where are those defined?

1 Like