C3_W2_Collaborative_RecSys_Assignment: Wrong value. Expected 27, got 0.0. Check the regularization term

I see many users have submitted the same problem.

While running this below I get the correct results:

Evaluate cost function

J = cofi_cost_func(X_r, W_r, b_r, Y_r, R_r, 0);
print(f"Cost: {J:0.2f}")

but then, when regularization is added on the next step - I get the same result as before without regularization:

Evaluate cost function with regularization

J = cofi_cost_func(X_r, W_r, b_r, Y_r, R_r, 1.5);
print(f"Cost (with regularization): {J:0.2f}")

and therefore with the next step, I get an error message:
AssertionError Traceback (most recent call last)
1 # Public tests
2 from public_tests import *
----> 3 test_cofi_cost_func(cofi_cost_func)

~/work/public_tests.py in test_cofi_cost_func(target)
14 J = target(X_r, W_r, b_r, Y_r, R_r, 2);
15 assert not np.isclose(J, 13.5), f"Wrong value. Got {J}. Did you multiply the regularization term by lambda_?"
—> 16 assert np.isclose(J, 27), f"Wrong value. Expected {27}, got {J}. Check the regularization term"

AssertionError: Wrong value. Expected 27, got 0.0. Check the regularization term

It appears your code isn’t correctly computing the unregularized cost and then adding the regularized cost.

Hi TMosh,

I get the correct result while computing unregularized cost. It seems to be that the piece that is supposed to add regularization doesn’t work. I have tried in several browsers already and encountered the same problem. Can you actually see my code? Or can I share it anyhow with you? It is done following all tips, I am already clueless what else can I do to fix it It looks to me like a bug.

Really hope to get help with this asap

Have a nice day!

1 Like

I do not see any relationship between what browser you use and whether you wrote the correct code for the math.

1 Like

Please check your forum personal messages.

Update for those who find this thread later:

The regularized part of the cost term needs to use the “lambda” parameter.
See the hints in the notebook for details.

Hey TMosh, I tried the same thing but it isnt working, I did use the lambda parameter in the regularised cost but the same error keeps popping up

1 Like

@NATHAN_CHRISTOPHER_M, please post a screen capture image that shows the error you are seeing.

Hello, I am facing the same issue with the error message shown in the screenshot, please if someone could help.

1 Like

Note that it isn’t the same error message.

  • The OP’s error was “expected 27, got zero”.
  • Yours is “expected 27, got 270”. The causes can be completely different.

The test your code fails is given in the public_tests.py file, under the test_cofi_cost_func() function.

Here is a quote from that test, showing the data it uses and the test that is failing.

You should be able to debug the issue from here.

1 Like