Week 2 Ex8 Error in Regression Model

Hi, all.

I have been working on week 2’s programming assignment and I have passed all the tests up to and including the model test.

When I run the regression model, it says

ValueError Traceback (most recent call last)
in
----> 1 logistic_regression_model = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.005, print_cost=True)

in model(X_train, Y_train, X_test, Y_test, num_iterations, learning_rate, print_cost)
38 w = params[“w”]
39 b = params[“b”]
—> 40 Y_prediction_test = predict(w, b, X_test)
41 Y_prediction_train = predict(w, b, X_train)
42 # YOUR CODE ENDS HERE

in predict(w, b, X)
22 # A = …
23 # YOUR CODE STARTS HERE
—> 24 A = sigmoid(x.T * X + b)
25
26 # YOUR CODE ENDS HERE

ValueError: operands could not be broadcast together with shapes (3,) (12288,50)

I don’t know where I messed up because all of my other tests passed.
Thanks for your help!

Do I use a dot product for w.T and x instead of x.T times X?

You should not have to change the code in predict. It was correct before. The problem is that you are passing it bad parameters. Check carefully the usage of the variables parameters and params. One is a global variable and one is a local variable. You are probably referencing the wrong one someplace in your model function.

1 Like

I think I fixed it, I tried dotproduct of w.T and X and it seems to work well now. Now, I am getting 99% and 70% for my training and testing.

I don’t think its params problem because they asked me to use ‘params’. I think i was getting the params partially wrong because now im getting [1,1,0]