# C3_W2_Collaborative_RecSys_Assignment Last Checkpoint: 27 minutes ago

Am getting a Cost with Regularization of 157.9 vice 28.09.
something wrong with my regularization code but have checked against hint and can’t find error. Please help.
Mike

1 Like

I am also stuck on this. I’ve went through the hints but still getting errors

1 Like

Hi!

@Michael_Crabtree @nick_j Can you send me your code in a direct message so I can take a look?

1 Like

Just sent over a message. Appreciate the help.

1 Like

“Removed Student Code” - Mentor Edit

1 Like

Hi!

You’re dividing the regularization terms by 2 then dividing the entire cost by 2.
By doing the operations in this order the regularization terms effectively get divided by 4.

You can either not divide the regularization term by 2 and divide the entire total cost by 2 at the end Or you can do the cost division by 2 then calculate the regularization term.

3 Likes

Sam, I have tried everything you suggested but keep getting wrong answers. This line of code is keeping me from completing the course.
Can I send you my notebook to review? If so, please tell me how to do that.

1 Like

Hi!

It’s good to review the function that is being implemented:

This can be rewritten as:

1/2 * ( \sum_{(i,j):r(i,j)=1} (w^{(j)} \cdot x^{(i)} + b^{(j)} - y^{(i,j)})^2 + \lambda \sum_{j=0}^{n_{u} - 1} \sum_{k=0}^{n-1} (w_k^{(j)})^{2} + \lambda \sum_{i=0}^{n_m - 1} \sum_{k=0}^{n-1}(x_k^{(i)})^{2})

And further rewritten:
1/2 * ( \sum_{(i,j):r(i,j)=1} (w^{(j)} \cdot x^{(i)} + b^{(j)} - y^{(i,j)})^2 + \lambda*(\sum_{j=0}^{n_{u} - 1} \sum_{k=0}^{n-1} (w_k^{(j)})^{2} + \sum_{i=0}^{n_m - 1} \sum_{k=0}^{n-1}(x_k^{(i)})^{2}))

make sure the 1 / 2 either happens at the end to the total sum or is distributed to all the terms.
also make sure that \lambda is applied to the total of the regularization terms or applied to each of the regularization terms separately.

I suggest individually applying the 1/2 and \lambda to each of their appropriate terms first, then try to simplify after.

1 Like

It seems the second equation is a bit long for the format, but you can hover over it and move the slider to the right to see the entire equation.

1 Like

Thank you, Sam.
I finally got it.
Mike

1 Like

Thank you for this suggestion. I was making this mistake.

1 Like

I have the same problem, can you give me a hand with the code
to solve the error. I am stuck

1 Like

Hi!
I have the same problem, can you give me a hand with the code
to solve the error. I am stuck

1 Like

Hi!

Send me your code in a direct message and I’ll take a look

1 Like

I am also stuck in this lab - followed carefully the hints and have not been able to figure out how to get to the correct expected cost after adding the regularization term. Have been looking into this for a few hours and could not get to the expected output. Please help - is there a way i can share my code with someone to give it a check?

1 Like

For anyone who in the future runs into this issue - do not waste hours chasing down the errors introduced by the code suggested there in the hints section after adding the regularization term. The best and simplest way to code this is using vectorization - simple and elegant without that complicated nested loops etc. Just look at the code for the vectorization section of this lab assignment and apply it for the rest of the sections - just 2 lines of code and you get the correct values without and with regularization.

2 Likes