C3_W2_Collaborative_RecSys_Assignment problema

Hi there! I cannot understand where is the problem. Thx!

I read another topics with similar problem but I can’t get the reason…


Hi @Marc_Oliveras ,

Please double-check if you have correctly implemented the regularization term in the function cofi_cost_func() . You are getting the same cost even when passing the regularization.


Hi @Mujassim_Jamal , I don’t understand you. I can’t change this formula because it comes by default from the assignment.


You don’t have to change anything in the cells where the evaluation is happening. The problem lies in the cofi_cost_func() function in the Exercise 1 section of this assignment. Please make sure whether you have added regularized cost at the end in the function or not.


Hi @Mujassim_Jamal ,
Got it! Thx!

1 Like

Hi Marc, I am having the same issue as you. Would you be able to share a screenshot of how you fixed it? I would be grateful. Thank you

1 Like

Do not post your code on forums as it violates the code of conduct.


Hii there! After adding regularization term as mentioned in the formula, I am getting cost with regularization as 157.90. I am unable to fix the issue. Please help me with this soon. Thanks.

1 Like

Sounds like you made a mistake in implementing the regularized term.

1 Like

Can I share screenshot? It’s correct as per my knowledge.

1 Like

Click on my profile and send it to me via DM.

1 Like

this is what I get too even if I just use what was provided in hints.

1 Like

It says that “Note that you should be accumulating the cost for user 𝑗 and movie 𝑖 only if 𝑅(𝑖,𝑗)=1.” I interpreted this as if R[i,j] == 1:, and then my code. This made me get 20.88 on the “# Evaluate cost function with regularization” code block. If I take this out, I also get 157.90. What should I do? :question::question::question:

Hello @BrunoPup115,

You are not the first one to ask about 157.9. Based on that, I would suggest you to check out the formula again. There are two square brackets, and we finish computing the first one, and then we compute the next, and then we add the two up. We don’t mix them up.


PS: rule is rule, so I still need to edit your post to remove that :wink: :wink:

1 Like

Then I get this:

But this still gives me 20.88. What should I do?

If you planned to FINISH the first bracket, and then FINISH the second bracket, and then sum them up, there should have been three steps only. However, interestingly, from your prints, you had four steps. Why don’t you literally FINISH one bracket at a time, such that after the sum, you won’t do any additional thing?

I can’t tell you where the bug is since it’s your problem to solve. My suggestion is, for that exercise,

  1. Backup your current code
  2. Remove your current code from the lab. If you cannot fix the current code, then give us a new chance.
  3. Forget about how you implemented it previously. Give us a new start instead of a straight way to repeat the same mistake.
  4. From now on, forget about all simplification tricks. No tricks. Just one bracket after another.
  5. Implement the first bracket
  6. Move the cursor to the end of the last line of code for the first bracket, then press enter twice to make sure the second bracket begins COMPLETELY AFTER the code for the first bracket.
  7. Implement the second bracket
  8. Implement the sum

Let’s see what will happen.


PS1: My steps 1 to 3 are one general way to get out from a code trap set up by our own belief that our code is correct or reasonable, when nobody can tell us the answer. It works better if we can give ourselves a break before starting, so that we can refresh ourselves.

1 Like

I looked at the hint, and that helped, so now I am getting the “Evaluate cost function with regularization” block correct, but on the “Public test” block, it says

AssertionError                            Traceback (most recent call last)
<ipython-input-55-1b3acfa244cb> in <module>
      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

(See attached image)

Nevermind. I figured it out. :smile:

I have been getting this error. I have infact re-written the code multiple times, checked the indentation and still could not get it working. Can you please let me know how you solved this?

I am facing same problem. Can you please share how did you make Assertion Error go away?