# Week 2 Assignment Exercise 8 - model

Hi, I am getting the following error on the Week 2 Assignment Exercise 8 - model. Please let me know what can I do to get rid of this 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)
113 y_test = np.array([0, 1, 0])
114
→ 115 d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=0.01)
116
117 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
38 w, b = initialize_with_zeros(2)
—> 39 params, grads, costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost=False)
40
41 w=params[‘w’]

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)
38
39 # YOUR CODE ENDS HERE

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

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

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

Your w value is the wrong shape by the time you call propagate from model. Note that the bug is not in propagate: it only takes the w and X values as input. So where is the shape of w determined? It is where you call the initialize routine, right? So that means you probably passed the wrong value for the dimension argument. E.g. maybe you referenced the global variable dim, which has nothing to do with the actual shape of the “sample” matrix X_train which is passed to the model function.

2 Likes

Thank you for the detailed reply, it helped me to resolve the problem.