Week 2 _Final Assignment _ Merge All functions in the Model

Can some one please help me with this, I am stuck here---->

GRADED FUNCTION: model

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):
“”"
Builds the logistic regression model by calling the function you’ve implemented previously

Arguments:
X_train -- training set represented by a numpy array of shape (num_px * num_px * 3, m_train)
Y_train -- training labels represented by a numpy array (vector) of shape (1, m_train)
X_test -- test set represented by a numpy array of shape (num_px * num_px * 3, m_test)
Y_test -- test labels represented by a numpy array (vector) of shape (1, m_test)
num_iterations -- hyperparameter representing the number of iterations to optimize the parameters
learning_rate -- hyperparameter representing the learning rate used in the update rule of optimize()
print_cost -- Set to True to print the cost every 100 iterations

Returns:
d -- dictionary containing information about the model.
"""
# (≈ 1 line of code)   
# initialize parameters with zeros 
# w, b = ...

#(≈ 1 line of code)
# Gradient descent 
# parameters, grads, costs = ...

# Retrieve parameters w and b from dictionary "parameters"
# w = ...
# b = ...

# Predict test/train set examples (≈ 2 lines of code)
# Y_prediction_test = ...
# Y_prediction_train = ...

# YOUR CODE STARTS HERE
w, b = initialize_with_zeros(4)
parameters, grads, costs = optimize(w,b,X_train, Y_train, num_iterations, learning_rate)
w = params["w"]
b = params["b"]

print(X_train.shape)

# YOUR CODE ENDS HERE
Y_prediction_test = predict(w, b, X_test)
# Print train/test Errors
if print_cost:
    print("train accuracy: {} %".format(100 - np.mean(np.abs(Y_prediction_train - Y_train)) * 100))
    print("test accuracy: {} %".format(100 - np.mean(np.abs(Y_prediction_test - Y_test)) * 100))


d = {"costs": costs,
     "Y_prediction_test": Y_prediction_test, 
     "Y_prediction_train" : Y_prediction_train, 
     "w" : w, 
     "b" : b,
     "learning_rate" : learning_rate,
     "num_iterations": num_iterations}

return d

I get an error →
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 2 into shape (4,1)

Hi @sufiyan.saqib, I would check the shape of w prior the reshape operation:

print(w.shape)
print(w)

Check if the above outputs are consistent with what you would expect for w.

Note that if you’ve pasted your actual code it is incomplete, for example, you haven’t initialized w and b.

The mistake i was doing was using :-
w = params[“w”]
b = params[“b”]

Where as :-
w = parameters[“w”]
b = parameters[“b”], was supposed to be used. This was giving me the shape error