Problem converting probabilities A[0,i] to actual predictions p[0,i] Logistic Regression with a Neural Network Mindset programming assignment

What’s wrong with this code?

{moderator edit: code removed}

It gives following errors when trying to compile next cell

ValueError Traceback (most recent call last)
in
2 b = -0.3
3 X = np.array([[1., -1.1, -3.2],[1.2, 2., 0.1]])
----> 4 print ("predictions = " + str(predict(w, b, X)))
5
6 predict_test(predict)

in predict(w, b, X)
23 # YOUR CODE STARTS HERE
24
—> 25 A = sigmoid(np.dot(w.T,x) + b)
26 # YOUR CODE ENDS HERE
27

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

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

Python is case sensitive. x is different from X. Check your sigmoid implementation in predict function.

Best,
Saif.

The error here is in the calculation of sigmoid, the np.dot(w.T, X) their shapes are not as suppesed to be. For eg. If w.T is MxN then X needs be (any size) x M, the column dimension of the second matrix needs be same as the row of the first matrix in the dot product.

Thanks a lot. You saved my day.!!!

@Kalyana_Chakravarthy, in the future, please do not post your code on the forum. That’s not allowed by the course code of conduct.

If a mentor needs to see your code, we’ll ask you to send it via a private message.

Posting the error messages and assert outputs is almost always sufficient for the mentors to understand the mistake.

@TMosh can you let me know what to do if I get stuck up with some error in my code at some point?. Is there a way to contact a mentor directly without posting the error/problem, kindly let me know. By far the mentors have been doing a great job troubleshooting.

You can post your error messages, and any asserts.
If a mentor needs to see your code, they’ll ask you to send it via a private message.

Mentors are not supposed to encourage sharing code on the forums. It violates the code of conduct.