C3_W2: Applying Regularization Still getting error

Hi there,
I am working on C3_W2. The code passed the test without regularization but when I include regularization parameter it does not work. I am including the regularization term but still getting an error. I am getting AssertionError: Wrong value. Expected 27, got 270.0. Check the regularization term. Seems like the cost of non-regularization is 0 when I put regularization term.

Need help please.

Got it working. I was multiplying lambda with an extra 1/2 which was provided in the hint.

Can you elaborate on what you did ? Because Im having the same issue. Using the hint, I still get an error

Having the same issue here, how can we correct this?

Tip: Check your use of parenthesis.
For example, if you were computing the cost, then 1/2*m is a lot different than 1/(2*m).

Look for similar types of issues.

Also be sure you’re multiplying by lambda_ when necessary.

I just worked it out.
you simply add the line of J+= code in the hint below J=J/2,
don’t replace the non-regularized version of the code.


It wooooorks! Thanks bro! :wink:

What exactly we have to do?

The regularized functions start by calling the non-regularized functions, then you add code to compute the regularized parts, and add them to the unregularized parts.

1 Like

Thank you so much pal

Thank you so much. It worked.

{moderator edit: code removed}

Please do not post your code on the forum.
This is a place to ask questions. Sharing your code is not allowed.

I am not sure what you mean here. Since we are not allowed to post code here, asking again:

The code without regularization works. When I add the code for regularization (and keep the non-regularization code), I get 157.90 (Cost with regularization) whereas the expected output is 28.09 ).
When I comment out the non-regularization code and just have the regularization code, I get an output of 144.23 as cost with regularization.

Unsure what else to do. Please provide Hints. Thanks.

I went back to the class notes to look at the cost function and think the code is doing what we learned but not giving the correct results with regularization: {moderator edit: code removed}

Still need help…

Hi @AjayaGummadi,

Please check out this post and pay attention to not mixing the regularization term into the error term. Note the two brackets in the formula. We finish computing the first bracket, and then we compute the second, and finally add both together.


@AjayaGummadi, as previously mentioned, please do not post your code on the forum.
Thank you.

This hint alone help many I guess !! :smile:
it would be really great if this hint gets added to the the portal hints section.

Hey! hop you all doing fine, I’m getting this error in test case, can anyone suggest me what is going wrong depite the code produces the same expected values, I’m getting confused about it.I can’t even change the atol=1e-8 to higher accuracy in testcasefiles. where should I look for this error in my code??

The last post is repeated: C3 W2 RecSysNN Assignment problem