Problem with Unit Test code: Week 3 practice lab: logistic regression

Hi,

It looks like the unit test code in my workspace is maybe messed up, as in overwritten? Is that possible that the unit test code is wrong or changed?

The notebook says the expect output is:

dj_db at test w and b (non-zeros) -0.5999999999991071
dj_dw at test w and b (non-zeros): [-44.8313536178737957, -44.37384124953978]

That’s the answer I get. But the unit test code is checking for a different value:

assert np.isclose(dj_db, 0.28936094)

There are multiple tests, and they all expect different results.

Yes, I under there are multiple tests. Here’s the one whose value is hard-coded to the answer that is different from the answer writen right on the screen:

def compute_gradient_test(target):  


...


assert np.isclose(dj_db, 0.28936094), f"Wrong value for dj_db. Expected: {0.28936094} got: {dj_db}"

Found it. Code error. The algorithm I wrote worked for shape (100,2) but not (100,3) which is what the test expects. A bit sneaky as Andrew talked about 2 independent variables in his lectures and labs.

1 Like

Good catch.

Tip: Your code should ALWAYS assume that it needs to work with any size and shape of data.