Hi! I need some help here.
All tests from previous exercises passed, and the outputs match with the expected values, but I’m getting this error here:
The error:
in propagate(w, b, X, Y)
29 # cost = …
30 # YOUR CODE STARTS HERE
—> 31 A = sigmoid(np.dot(w.T, X) + b)
32 cost = np.sum((-1/m)*((Y * np.log(A)) + ((1 - Y) * np.log(1 - A))))
33 # YOUR CODE ENDS HERE
<array_function internals> in dot(*args, **kwargs)
ValueError: shapes (1,12288) and (4,3) not aligned: 12288 (dim 1) != 4 (dim 0)
My code to excercise 8:
w, b = np.zeros((num_pxnum_px3,1)), 0
params, grads, costs = optimize(w, b, X_train, Y_train, num_iterations=100, learning_rate=0.009, print_cost=False)
w, b = params[“w”], params[“b”]
Y_prediction_test = predict(w, b, X_test)
Y_prediction_train = predict(w, b, X_train)
Your mistake is that you are referencing the global variable num_px to set the size of w. In the test case here, the number of “features” in the X_train matrix is not 12288, but is 4. So that’s why your code fails. We are trying to write “general” code here, meaning that it will work with any size of inputs. So it is a mistake to make any fixed assumptions about the sizes of things. Instead use the “shape” attribute of the inputs to do things like initialize w.
1 Like
Thanks a lot! I will try again and submit.
Also note that you are making some additional mistakes in that code: you are hard-coding the number of iterations and learning rate on the call from model to optimize. The values that are actually passed into model will be ignored and you will always run 100 iterations, e.g., and will never print the cost values.
Also note that you should not be using np.zeros to do the initialization of w and b. You already wrote a function to do that, right?
Once you have passed the grader on this, please do us a favor and remove the source code from your original post. We don’t want to leave solution code published on Discourse or in other public places. Thanks!
1 Like
Thaks again. Can you explain how I can edit the original post? I can’t see this option and I have no permission to delete.
hi @braiangama, in your post you should see a “pencil” at the bottom of your post like the one below. That only appears in your posts obviously ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/google/slight_smile.png?v=9)
1 Like
This option is not showing for me.
Oh, sorry, Discourse has some funny rules for relatively new users. I think they only give you a short time span in which to edit something and then they close it. I’m not sure why they do that, but I think they relax the restrictions as you create more posts and replies. They have this concept of “trust level” and as your trust level increases, you get more capabilities.