(Week 2 - ex 8) Merge functions

I can pass all the tests saperately but getting an error in merging function. please help me out. thank you!!

the error is:

train accuracy: 66.66666666666667 %
test accuracy: 66.66666666666667 %
AssertionError Traceback (most recent call last)
in
----> 1 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
117 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
118 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
→ 119 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
120
121 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"

AssertionError: Wrong values for d[‘w’]. [[ 0.28154433]
[-0.11519574]
[ 0.13142694]
[ 0.20526551]] != [[ 0.00194946]
[-0.0005046 ]
[ 0.00083111]
[ 0.00143207]]

Hi @jaydippokiya. You are not allowed to post you work as It is in violation of the Coursera Code of Conduct. Please take down your post and start again. And, for the benefit of those searching for assistance on similar issues, please identify the exercise number in the topic heading.

This post may be useful in diagnosing your problem.

1 Like

I apologize for violating the code of conduct. I have edited the post.

I read the solution but I believe it is not related to the problem I am facing!!

I am getting the wrong values but the dimensions are matching.

That post was intended to be more generally useful for you. Often, when tests on the individual functions pass but there is a failure when running the function that brings them all together, the problem (more often than not) lies in how the functions are applied in Python. For example, one may “hard-code” an argument to a function called within the merging function, rather than inherit the argument from the “merging” function. The point is to do the kind of code review suggested in that previous post.

1 Like

the error mentioned above (i.e. value of parameter ‘w’ is not matching with the actual one) vanishes if I take learning rate to be 0.00005 in ‘optimize’ function. however, new error show up where ‘w’ is matching with the actual parameter but there is a slight difference in the value of parameter ‘b’. And I believe, I am not allowed to change the learning rate.

AssertionError Traceback (most recent call last)
in
----> 1 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
119 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
120
→ 121 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"
122
123 assert type(d[‘Y_prediction_test’]) == np.ndarray, f"Wrong type for d[‘Y_prediction_test’]. {type(d[‘Y_prediction_test’])} != np.ndarray"

AssertionError: Wrong values for d[‘b’]. 0.0008311670001839005 != 0.000831188

@jaydippokiya you should not hardcode any value for learning rate, num_iterations, etc. Those are set in the test code, if you hardcode any of those values you will have mismatches between the expected result from the test and the one from your code. If you have predefined any of those parameters inside model you should review your code.