Expected Output matches but Unit Test failed. C1_W3

I am quite confused. I looked at the hints, cross checked against previous optional labs, checked my spacing, indentation and line breaks.

As far as I am aware, this should work.

EDIT: Took out picture of my code as I realised it is not allowed. See image of error below.

Apparently there is an error in your code.

1 Like

I know that much already, what sort of error would allow me to get the expected output but fail the unit test?

There are many possible errors.

The initial test uses weight and bias values of 0.

Since multiplying by zero always gives zero, and adding zero changes nothing, the initial test doesn’t prove much about how well your code works.

This is the exact error I am getting, any suggestion on where to go from here? I have rewatched the relevant Week 3 videos but cannot seem to figure this out.

image

Hello @Muhammad_Ali7,

Debugging is part of the assignment and it’s usually not the most straight forward part, and sometimes I would recommend learners to take a break from it and come back later because this resets our focus so we can look at our code differently in the next time.

There is already some time since you posted the question, and I think you might take the advantage of that and have a look at your code again.

As said, debugging is part of the assignment, and I always suggest learners to assign some numbers to the variable and “run the code in their mind”. The numbers could be simple integer values so they are easy to manipulate in mind or on paper. For example, the function in question has 4 required arguments:

X, y, w, b

Then a good start could be to consider a dataset of 2 samples and 2 features, so that X has two rows and two columns, y has two values, w has two values, and b is a value. For example, we can assign w to be [1, 2], and b to be 1 so that they are all simple numbers.

Before “running the code in mind”, we need a baseline to compare with, right? So we first calculate the cost using the formula provided in the exercise’s description, then we “run the code” in mind or on a paper, and see if we will get to the same answer as the baseline. Through this process, you definitely will find out what you have mistakenly added, missed or done.

Debugging is not favourable, but it’s part of life. Good luck @Muhammad_Ali7 :wink:

Raymond

1 Like

Thank you for your very detailed and thoughtful response. I have gotten somewhat closer to finding the solution. I will do what you mentioned, appreciate your thorough reply.

1 Like