C3_W2 Excercise 1

Hello,
On exercise 1 when adding regularization, My output is 157.90 vs 28.09 expected.
Appreciate your help

Hi @Manuel_Trujillo ,

If your code has calculated the cost correctly when the regularization is set to 0, then, the error for missing the target output of 28.09 when regularization is 1.5 is likely to be the calculation of the regularization term. Check your code against the formula and use round brackets to enforce the correct order of expression, ie. the operator * or / has higher order of execution than + or -

Thanks Kic,
It worked before applying regulation Cost: 13.67. But when I added the regulation, the numbers didn’t match
I’m including a snapshot of my code

Appreciate your help

{moderator edit: code link removed - do not share your code in public}.

Hi @Manuel_Trujillo ,

Could you send me a direct message with the code for that function.

Thanks Kin,
See code:
J += np.square(r * (np.dot(w,x) + b_j - y ) ) + (lambda_/2) * (np.sum(np.square(W)) + np.sum(np.square(X)))

Hi @Manuel_Trujillo ,

Let the variable reg be the regularization term:

reg = lambda_/2*(np.sum(np.square(W))+np.sum(np.square(X)))

You use np.square(r * (np.dot(w,x) + b_j - y ) ) to calculate the cost, but J is half of cost, a scaled down value :

J = cost/2

So J with added regularization is:

J = J + reg

Thanks
It worked

Thanks,

Manny

Also receiving errors on this problem, this is the error message. Could someone advise?

Error msg: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'reshape'

Hello colleagues,

I have received the wrong cost with regularization as well: 144.23 instead of 28.09 expected. My code with added regularization is: J += (lambda_/2) * (np.sum(np.square(W)) + np.sum(np.square(X))). Could you please help to receive the expected output?

Thank you,
Kind regards,
Anna

Hi,
I am also having the same problem. Can you tell me how to resolve this?

Hi,
I ahve already resoved the problem.
Thanks