# C3\_W2\_Collaborative\_RecSys\_Assignment: Wrong data for Regularization

**URL:** <https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444>\
**Category:** Unsupervised Learning, Recommenders, Reinforcement\
**Tags:** week-module-2\
**Created:** [November 6, 2024, 5:13pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444 "2024-11-06T17:13:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravivemuri](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@ravivemuri](https://community.deeplearning.ai/u/ravivemuri)\
**Post date:** [November 6, 2024, 5:13pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/1 "2024-11-06T17:13:27Z")

</div>

Hi,  
I have an issue for the C3\_W2\_Collaborative\_RecSys\_Assignment  
Exercise 1  
In the steps it is asked to compute cofi\_cost\_func with and without regularization  
In the function towards the end, where J is computed,  
As it asks to compute J without regularization first followed by with regularization, and since it is the same function call,  
I added like this  
if(lambda\_ == 0):  
J +=   
else :  
J +=

Is this approach correct?

I dont get any syntax error, but the value of J that is returned WITH regularization is wrong.

I am getting 144.43, whereas expected is 28.09

Can you please help me where I am going wrong?

Regards  
Ravikiran

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 6, 2024, 5:17pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/2 "2024-11-06T17:17:06Z")

</div>

That’s not a necessary approach.

I recommend you implement only the code for the regularized cost, and if lambda = 0, then that contribution will be zero because it is a multiplier.

> [@ravivemuri](#):
>
> the value of J that is returned WITH regularization is wrong.

That indicates your calculation is incorrect.

---

<div class="post-metadata">

**Author:** ![ravivemuri](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@ravivemuri](https://community.deeplearning.ai/u/ravivemuri)\
**Post date:** [November 6, 2024, 5:32pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/3 "2024-11-06T17:32:27Z")

</div>

But then I am getting error for the previous one where we calculate WITHOUT regularization where the expected output is 13.67 which I got with the different formula?  
I guess there are two different formulas for with and without.  
Is that not correct?

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 6, 2024, 6:43pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/4 "2024-11-06T18:43:45Z")

</div>

There is only one equation for the cost.

This image is from Section 4.1 of the notebook:

 ![image](https://global.discourse-cdn.com/dlai/original/3X/c/d/cd5718678ba7b95bf2560ffee220adb20dd39093.png)

The part labeled A is the unregularized cost.

The part labeled B is the regularized portion of the cost.

If the cost function is called with the lambda parameter set to 0, then the B portion will compute to 0, so the function returns only the unregularized cost.

If you don’t get the correct results for the A portion, there is an error in your code.

---

<div class="post-metadata">

**Author:** ![ravivemuri](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@ravivemuri](https://community.deeplearning.ai/u/ravivemuri)\
**Post date:** [November 6, 2024, 7:30pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/5 "2024-11-06T19:30:24Z")

</div>

I am kind of little lost.  
From the “hints” portion of the exercise, it showed two different equations for w/o regularization and with regularization.  
As per your tip, I should still use the equation for “regularization” and since lambda will be 0, it should work for w/o regularization also?

Let me try

Ravikiran

---

<div class="post-metadata">

**Author:** ![ravivemuri](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@ravivemuri](https://community.deeplearning.ai/u/ravivemuri)\
**Post date:** [November 6, 2024, 8:13pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/6 "2024-11-06T20:13:42Z")

</div>

I am not sure if I am getting the correct value after following the equation.  
I am stuck at this place.  
I am aware that I am not supposed to paste the code here, but please delete it after I get the fix for this.  
Please let me know what I did below is correct?

{mentor edit: code removed}

With regularization, I am getting a value of 302.13, while expected is 28.09

Please help

Ravikiran

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 6, 2024, 8:34pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/7 "2024-11-06T20:34:14Z")

</div>

Please do not share your code on the forum. That’s not allowed by the Code of Conduct.

You can send me your code via a private message, I’ll send you instructions in a moment.

Also note that the “preformatted text” tag should be used so that your code indentation is preserved.

---

<div class="post-metadata">

**Author:** ![ravivemuri](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@ravivemuri](https://community.deeplearning.ai/u/ravivemuri)\
**Post date:** [November 6, 2024, 9:27pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/8 "2024-11-06T21:27:47Z")

</div>

Thank you, yes I am kind of aware not to do. Probably I should have asked how to do private message.  
Sorry and thank you

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 7, 2024, 12:03am UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/9 "2024-11-07T00:03:17Z")

</div>

Report back for students who find this thread later:

- Be sure that if you compute the regularized cost for all values of X and W, that you do so only once (outside of any nested for-loops).

---

<div class="post-metadata">

**Author:** ![LaurenRitter](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/laurenritter/32/111104_2.png) [@LaurenRitter](https://community.deeplearning.ai/u/LaurenRitter)\
**Post date:** [February 18, 2025, 9:56pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/10 "2025-02-18T21:56:37Z")

</div>

Hi @TMosh I was wondering if you might be able to help me here as well? I have been struggling on this lab in particular this week and am truly unsure what I might be doing wrong, even after studying the tips provided.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [February 18, 2025, 10:13pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/11 "2025-02-18T22:13:52Z")

</div>

What problem are you having specifically?

Please don’t post your code, just a description of the issue, and a screen capture image of any error messages or test results you see in your notebook.

---

<div class="post-metadata">

**Author:** ![LaurenRitter](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/laurenritter/32/111104_2.png) [@LaurenRitter](https://community.deeplearning.ai/u/LaurenRitter)\
**Post date:** [February 19, 2025, 4:23pm UTC](https://community.deeplearning.ai/t/c3-w2-collaborative-recsys-assignment-wrong-data-for-regularization/719444/12 "2025-02-19T16:23:58Z")

</div>

Thank you for responding! I slept on it and this morning realized it was the order in which I included the regularization term. Once I fixed this, all the tests passed. Thanks for your time, cheers!
