W2_A2_Ex-8

Hi - I managed to pass my Assignment 2, however still couldn’t get the model to work. This is my code, and below errors given… any help?

{moderator edit - solution code removed}



ValueError Traceback (most recent c

all 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['c

osts’]. {type(d[‘costs’])} != list"

in model(X_train, Y_train, X_test,

Y_test, num_iterations, learning_rate, print_cost)

42 b = params[“b”]

43

—> 44 Y_prediction_test = sigmoid(np.dot(w, X_test.T) + b)

45

46 Y_prediction_train = sigmoid(np.dot(w, X_train.T) + b)

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

ValueError:

That code for computing the predictions does not look correct to me. Here are the dimensions:

w is n_x x 1, where n_x is the number of features. That is 12288 for the actual images here. So it is 12288 x 1.

The dimension of X_train is 12288 x 209. So if you transpose it, you get 209 x 12288.

Now what happens if you try to multiply w \cdot X^T? That will be 12288 x 1 dot 209 x 12288 and it will simply throw an error, right?

Please compare that code to what you wrote in the propagate function for computing the output of the model.

Also note that you already wrote the predict function and can save yourself work by just calling it directly there. You don’t want the sigmoid output anyway, right? You want the “yes/no” form, which is what predict returns.