MLS course 1 Week 3 practice lab

How to overcome following error? Any guidance please.

Test your predict code

tmp_w = np.random.randn(2)
tmp_b = 0.3
tmp_X = np.random.randn(4, 2) - 0.5

tmp_p = predict(tmp_X, tmp_w, tmp_b)
print(f’Output of predict: shape {tmp_p.shape}, value {tmp_p}')



output and Error:
Output of predict: shape (4,), value [0. 0. 0. 1.]

AssertionError Traceback (most recent call last)
—> 11 predict_test(predict)

~/work/ in predict_test(target)
69 raise ValueError(“Did you apply the sigmoid before applying the threshold?”)
70 assert result.shape == (len(X),), f"Wrong length. Expected : {(len(X),)} got: {result.shape}"
—> 71 assert np.allclose(result, expected_1), f"Wrong output: Expected : {expected_1} got: {result}"
73 b = -1.7

AssertionError: Wrong output: Expected : [1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0] got: [0. 0. 0. 0. 0. 0. 0. 1.]

Predict function looks like the following:
{mentor edit: code removed}

Hello Dharani_Suresh_Babu,
As per community guidelines you are not supposed to send code here. If you need any help regarding the error you are getting, you can send the error what you got.

1 Like

Please do not post your code on the Forum. That’s not allowed by the course Honor Code.
I have edited your message to remove the code.

The most likely error is incorrect indentation in your code in the for-loops, so that the f_wb or p[i] calculations give the wrong results.

1 Like

Thanks for your suggestion and sorry about that. will make sure next time.

Week 3 Lab: Logistic Regression,
I have a problem with the prediction function: following the implementation, I have wrong output.