This is for exercise 8 - model… all the previous exercises passed…
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)
37
38 # YOUR CODE STARTS HERE
—> 39 Y_prediction_test = predict(w, b, Y_test)
40 Y_prediction_train = predict(w, b, Y_train)
41 # YOUR CODE ENDS HERE
in predict(w, b, X)
16 m = X.shape[1]
17 Y_prediction = np.zeros((1, m))
—> 18 w = w.reshape(X.shape[0], 1)
19
20 # Compute vector “A” predicting the probabilities of a cat being present in the picture
ValueError: cannot reshape array of size 4 into shape (1,1)
1 Like
Make sure you have passed the previous exercises.
For Exercise 8, you have to use initialize_with_zeros
to initialize w
and b
, call optimize
function (without hard coding anything) for params, grads, costs
. And then use predict
function for Y_prediction_test
and Y_prediction_train
.
1 Like
Saif,
from exercise 7…output
predictions = [[1. 1. 0.]]
All tests passed!
I think I’ve done that correctly…
w,b = initialize_with_zeros(X_train.shape[0])
params, grads, costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)
w = params[“w”]
b = params[“b”]
Y_prediction_test = predict(w, b, Y_test)
Y_prediction_train = predict(w, b, Y_train)
thanks,
rick
1 Like
Your input to predict
function for Y_prediction_test
and Y_prediction_train
is wrong. It should take input (X), not output (Y).
2 Likes
Saif,
thank you! I thought it wanted Y since the functions used the labels… It would be helpful to clarify the comments to help the learner know what set to use.
thanks,
rick
1 Like
It is instructed in the predict
function, Exercise 7:
1 Like
Saif,
That’s not clear to me… X refers to the Variable being passed to the function… doesn’t mean that we would pass the X Training and Test sets… it would be better to have that comment in the comment area of the model (learner focus is on the model code not in the function calls at that point) vs in the function called or be explicit in saying that you want X data sets only… not sure that is the case…
thanks,
rick
1 Like
I understand your concern. However, in the world of Machine Learning, it is quite common to denote input data as X
.