ValueError Traceback (most recent call last)
<ipython-input-145-9408a3dffbf6> in <module>
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"
<ipython-input-144-df7a07c5017f> in model(X_train, Y_train, X_test, Y_test, num_iterations, learning_rate, print_cost)
44 b = params["b"]
45
---> 46 Y_prediction_test = predict(w,b,X_test)
47 Y_prediction_test = predict(w,b,X_train)
48
<ipython-input-143-fa9e124a5a8c> in predict(w, b, X)
17 Y_prediction = np.zeros((1, m))
18 print(w.shape)
---> 19 w = w.reshape(X.shape[0], 1)
20
21 # Compute vector "A" predicting the probabilities of a cat being present in the picture
ValueError: cannot reshape array of size 28 into shape (4,1)

I am getting this in Question 8 Model

I can see that in predict function It was given to reshape the weights to (X[1],1) Probably because of that its throwing this error and we are not supposed to change any code outside of the given area. Please Help.

I am assuming m is the number of training examples, I am initializing w as np.zeros((X_train.shape[0],X_train.shape[1])) weights with same dimension as X_train. m is basically X_train.shape[1] number of columns of X.

Hello,
I Initialized w and b with Initialize_with_zeros function and provided the dimension of w as X_train.shape[0] and it worked but I did not understand, we are running the model function only once whereas we have to initialize w and b for each training example (each image in the data) right ? ideally weight vector should be same dimension as X_train. What am I missing ?

No. We have to initialize w and b for each layer (hidden and output layers). In this assignment, we have only one layer model.

Again no. I guess you will learn more about the shape of weight and b in the upcoming weeks. For now, the shape of the weight is: (number of rows in X_train, 1).

In every iteration we have one training example that means one columns of X_train at a time got it. Thats why we need weights to be a row vector ! Makes sense thankyou.