W2 Logistic Regression w/ NN Mindset

I’m getting a dimensions error for model() that I don’t know how to resolve. I used some print statements to figure out what dimensions everything has in model().

From my understanding, the error indicates that w should be size (1, 4) so that when it’s transposed in predict(), it will be (4, 1) and can multiply with (1, 3).

However when w is passed into predict(), it’s already (4, 1) so when it is transposed it is (1, 4), which doesn’t work.

But if I remove the w.T in predict(), then my definition of A is incorrect and also predict() test cases don’t pass.

In model() I defined w to be w, b = initialize_with_zeros(X_train.shape[0]) since the comments said to use first dimension of X_train for dim.

In case I misunderstood “first dimension” as 0th index instead of 1st index, I still get the same error when I do w, b = initialize_with_zeros(X_train.shape[1]), which is “ValueError: shapes (1,7) and (4,7) not aligned: 7 (dim 1) != 4 (dim 0)”.

I would really appreciate some help on this! Thanks!

Resolved.

2 Likes

That’s great news that you found the solution under your own power. Yes, I added some print statements to show the shapes of everything in that test for model and here’s what I see:

model with num_iterations 50 learning_rate 0.01
X_train.shape (4, 7)
X_test.shape (4, 3)
Y_test.shape (1, 3)
before optimize w.shape (4, 1)
optimize with num_iterations 50 learning_rate 0.01
in model before predict call w.shape (4, 1)
predictions = [[1. 1. 0. 1. 0. 0. 1.]]
predictions = [[1. 1. 0.]]
All tests passed!

The only thing with a shape of 1 x 3 is Y_test.

1 Like