DL1 WK2 - Assignment

Hi all,

I am very new to this course and I am getting stuck at the Course 1/ WK2 asssignment: “Logistic regression with a Neural network mindset”.

I think i have written the code correct but its giving me an error.

My piece of code:**
{CODES REMOVED BY MODERATOR, REFRAIN POSTING GRADER CODES FROM ASSIGNMENT IN FUTURE}
YOUR CODE ENDS HERE

Error i am getting:


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

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 # cost = …
32 # YOUR CODE STARTS HERE
—> 33 A = sigmoid(np.dot(w.T,X)+b)
34 cost = -(1/m)np.sum(Ynp.log(A)+(1-Y)*np.log((1-A)))
35

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

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

Thanks all for the help!

@chichulito The ‘shape’ or dimension of your w and b matrices are wrong.

Keep in mind the set of W, b parameters that goes into your predict function (after initialization) is not the same as what comes out (you don’t want to try and ‘predict’ on all zeros, do you ?).

Think: Where/how can I find these updated/trained parameters ?

P.s. In the future, you are not supposed to post your code in the forum. I think one of the mentors/moderators will take issue with this.

Please note that X and X_train are different. Same for Y and Y_train.

1 Like

Thanks for the answers! I updated the variables and also updated w and b after running optimize(). It works now!