Exercise 1 requires regularization in first test

When I included the regularization term the first test works fine but when I comment it out it fails with

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

But the instructions say

First, develop the cost function without regularization. A test case that does not include regularization is provided below to test your implementation.

Hi @toontalk
I think the issue is that the test functions are swapped. The first test function:

run the test of the cofi_cost_func with the regularization term and print out the error (if the regularization term is missing), while the function that is below:

run the test without the regularization term.
Maybe swapping these lines would be a good solution that could correct the confusion.

1 Like


I saw the first test was calling a “target” function instead of “cofi_cost_func”, so inserting this patch

def target(X,W,b,Y,R, lambda_):
return cofi_cost_func(X,W,b,Y,R,lambda_)

got the test to work when I run it.

The rest of tests also run fine, without having to swap.

Hi @Jaume_Oliver_Lafont,

Yes, you are correct. I did not say that we have to do it it was rather a suggestion for the course administrators that they can change it in the future version of this assignment.

You can skip the first function test_cofi_cost_func and run it later after you add the regularization term to your cofi_cost_func function. Or if you run it earlier then just run it again to get rid of that error. It is a test function and it only checks if your code is correct.

My previous post was an explanation of the source of that error.

Thanks all! Great catch! I’ll submit a request to the developers to fix this in a future version of the assignment.

That’s the method the test cases use. As a general practice, I recommend you not modify it.

Ok, I see, thanks, @TMosh.

I believe one of the issues is the first assert in test_cofi_cost_func will always trigger and return 0 without the regularization term because R_r is an array of zeros.

This is still not fixed, which is disappointing.

I too got: “Wrong value. Expected 27, got 0.0” and I was pulling my hair out, and it wasn’t until I copy & pasted the exact code from the hints and saw it still had that same error that I came looking on the forum.
I had to figure out & include the regularization in my code for it to work.

Hi Nathan @evoalg, I am sorry to hear about that. Wendy had reported this issue, and i also tried to draw the course team’s attention about this again. Now I think the team is reprioritizing this but it may take some time because any change has to be carefully reviewed in order not to break something else down. Lastly, I want to say thank you for letting us hear your voice.


Thank you, Raymond, good to hear it’s being actioned. :smile: I just didn’t want others to go through that (thinking they were doing something wrong). It’s a wonderful course and loverly mentors and that was the only hiccup that I’ve encountered.

No problem Nathan. We are the same - we both don’t want others to go through that. I look forward to discussing with you on other questions about the last course, of course if there is any :slight_smile:

I also faced the same problem too I tried to solve it, but I got the same error every time. However, I will skip the lab and pass on to the next topic until the team fix the problem!


1 Like

Hello Nathan @evoalg, @saadoun123,

The team has made a change that will automatically apply to all new learners. For existing learners, however, they will only see the change if they manually get a new copy of the notebook.

The change is basically to reorder the testing cells so that

  • the tests for without-regularization will come first,
  • followed by the tests for with-regularization,
  • and lastly the public tests for with-regularization.

Here is how we can do to proceed:

  1. Since the change is only about reordering the cells, you may choose not to update the lab, but run the cells in the right order. I am sharing a screenshot of the right order here:

  2. If you want to update the lab, you may follow these steps which will ask you to rename your current notebook so that the system can give you a new one. Then you may copy your work from your current notebook back to the new one.

  3. Lastly, these changes DO NOT change the requirement that you need to add regularization to the cofi_cost_func after passing the without-regularization tests, in order to pass the rest of the tests.


P.S. I am making this post the solution so that others can quickly jump to here.

1 Like

Hello @rmwkwok,

Thanks for your reply,

Unfortunately, I’m still stuck on the same error. However, I followed your guidelines and still face the same problem where I got Cost (with regularization): 144.23 not as expected 28.


Hello @saadoun123,

  1. Why do you comment out the line that actually calculate the cost? I would have understood it if you commented out the line next to it for the without-regularization test, but for the one you actually commented out, I cannot understand.

  2. You only need to add the regularization once, not per user and per movie. Check out the formula above the exercise, and you will see that the “regularization part” does not belong to the summations (because there is no brackets)

  3. Regularization needs only one divided by 2. Becareful about this.

  4. We don’t post assignment code here, so I am removing it.

  5. Sorry but I have to close this thread since the discussion starts to derivate from the original topic. Please open a new thread, share the error messages if you have any follow-up question.

Good luck, and cheers,

1 Like