Assignment #1 – I am stuck on following:
Exercise 8 - model
{moderator edit - solution code removed}
Getting following 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)
34 #w,b = initialize_with_zeros(dim)
35 w,b = initialize_with_zeros(X_train.size)
—> 36 param, grads, cost = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)
37 w = params[“w”]
38 b = params[“b”]
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)
31 # YOUR CODE STARTS HERE
32 W_T = np.transpose(w)
—> 33 A = sigmoid(np.dot(W_T,X)+b)
34 #cost = -np.sum(np.dot(np.log(A).reshape(A.shape[1],A.shape[0]),Y)+np.dot(np.log(np.subtract(1,A)),np.subtract(1,Y).reshape(Y.shape[1],Y.shape[0])))/m
35 cost = -np.sum(np.dot(np.log(A),Y.reshape(Y.shape[1],Y.shape[0]))+np.dot(np.log(np.subtract(1,A)),np.subtract(1,Y).reshape(Y.shape[1],Y.shape[0])))/m
<array_function internals> in dot(*args, **kwargs)
ValueError: shapes (1,28) and (4,7) not aligned: 28 (dim 1) != 4 (dim 0)
Not sure what I am missing here .
Can anyone help me …