# Collaborative Filtering Assignment

**URL:** <https://community.deeplearning.ai/t/collaborative-filtering-assignment/416752>\
**Category:** Unsupervised Learning, Recommenders, Reinforcement\
**Tags:** week-module-2\
**Created:** [August 13, 2023, 8:24pm UTC](https://community.deeplearning.ai/t/collaborative-filtering-assignment/416752 "2023-08-13T20:24:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anubhooti\_pareek](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/anubhooti_pareek/32/51722_2.png) [@anubhooti\_pareek](https://community.deeplearning.ai/u/anubhooti_pareek)\
**Post date:** [August 13, 2023, 8:24pm UTC](https://community.deeplearning.ai/t/collaborative-filtering-assignment/416752/1 "2023-08-13T20:24:05Z")

</div>

Hi,

I am stuck at the Collaborative Filtering Recommendation System assignment. I was able to get the right output with regularization, but am unsure where should I add the regularization term? I am getting the wrong output when I add the regularization term.

---

<div class="post-metadata">

**Author:** ![AbdElRhaman\_Fakhry](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/abdelrhaman_fakhry/32/65768_2.png) [@AbdElRhaman\_Fakhry](https://community.deeplearning.ai/u/AbdElRhaman_Fakhry)\
**Post date:** [August 13, 2023, 9:12pm UTC](https://community.deeplearning.ai/t/collaborative-filtering-assignment/416752/2 "2023-08-13T21:12:21Z")

</div>

the regularization term is add it to the regular cost(just addition operation) like this equation

\underbrace{ \frac{\lambda}{2} \sum\_{j=0}^{n\_u-1}\sum\_{k=0}^{n-1}(\mathbf{w}^{(j)}\_k)^2+ \frac{\lambda}{2}\sum\_{i=0}^{n\_m-1}\sum\_{k=0}^{n-1}(\mathbf{x}\_k^{(i)})^2 }\_{regularization}

---

<div class="post-metadata">

**Author:** ![anubhooti\_pareek](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/anubhooti_pareek/32/51722_2.png) [@anubhooti\_pareek](https://community.deeplearning.ai/u/anubhooti_pareek)\
**Post date:** [August 14, 2023, 12:45am UTC](https://community.deeplearning.ai/t/collaborative-filtering-assignment/416752/3 "2023-08-14T00:45:46Z")

</div>

I did, I added the regularization term and got the following error:  
AssertionError Traceback (most recent call last)  
 in   
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"  
17  
18

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

---

<div class="post-metadata">

**Author:** ![anubhooti\_pareek](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/anubhooti_pareek/32/51722_2.png) [@anubhooti\_pareek](https://community.deeplearning.ai/u/anubhooti_pareek)\
**Post date:** [August 14, 2023, 5:29pm UTC](https://community.deeplearning.ai/t/collaborative-filtering-assignment/416752/5 "2023-08-14T17:29:55Z")

</div>

The issue is resolved. Thanks
