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

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

Just sent over a message. Appreciate the help.

“Removed Student Code” - Mentor Edit

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.

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.

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.

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.

Thank you, Sam.

I finally got it.

Mike

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

I have the same problem, can you give me a hand with the code

to solve the error. I am stuck

Hi!

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