Programming Assignment

I am not able detect error in my programming assignment. My code is correct. There is some issue in test code. There is need to troubleshoot the test code so it can run properly

Hi @Ayesha_Amjad1 ,

The test code has been in use since the course was launched in Aug 2022, and many learners have passed the lab assignment with flying colours.

The community members here are very helpful. All you need to do is to post the error traceback, they will do what they can to help with the diagnosis.

AssertionError Traceback (most recent call last)
in
8
9 # UNIT TESTS
—> 10 compute_cost_test(compute_cost)

~/work/public_tests.py in compute_cost_test(target)
24 b = 0
25 result = target(X, y, w, b)
—> 26 assert np.isclose(result, 2.15510667), f"Wrong output. Expected: {2.15510667} got: {result}"
27
28 X = np.random.randn(4, 3)

AssertionError: Wrong output. Expected: 2.15510667 got: 0.15761825329865956

This is error traceback

Hi @Ayesha_Amjad1,

Welcome to our community!

The error means that your code wasn’t implemented correctly, because in one of the test cases, when it expected for an answer of 2.15510667 , your solution returned 0.15761825329865956 which had underestimated it.

Note that it is part of your assignment to debug any problem in your solution, however, we can provide some suggestions:

  1. I have looked at the hint provided right beneath the exercise’s code cell and it has provided the skeleton of how your solution should look like. Please strictly follow it along with all the indentations (the spaces at the beginning of a code line). Then based on that skeleton, fill in the missing code. Note that indentation is a major source of error. The least is that you need to strictly follow the skeleton provided in the hint. Here is a 5-min post on what indentation is and how to indent.

  2. If you need more clues, print the inputs and all intermediate outputs. For example, if you print the inputs, the test case in question has only 5 samples and 2 features per sample, which is small enough for you to verify any intermediate output by hand. Then, according to the skeleton provided by the hint, there are 5 intermediate outputs (z_wb_ij, z_wb, f_wb, loss, loss_sum, total_cost) that were updated throughout the solution. You only need to print each of them each time it gets updated, so that you can inspect whether the updated values are as expected. Once you spot any unexpected update, you find the code line that needs correction. After you have passed all the public tests for this exercise, remember to remove all the print code as they will interfere with the autograder and fail your submission.

Good luck,
Raymond