I am having similar issues. I used the code in the hints and moved r * outside np.square(). I can match the  Cost = 13.67.
For  with regularization, the expected output is 28.09 but for that I get still get 13.67.
And, for the public test , I get the same Assertion Error @Anupama_Kota posted.
Please assist with regularization  and public test 
@Alan_Ravitz, what exactly do you mean by the numbers in the square brackets?
I’m not really sure TBH. I was concerned about what I can/can’t post here so I wasn’t more explicit the first time but let me paste a screenshot here
Posting images of the error messages is always allowed.
The test with lambda_ = 1.5 shows that your cofi_cost_func() doesn’t handle the regularization calculation correctly.
The notebook gives you all of the data for this test case, so you can calculate the regularized part by hand and then look at your code and instrument it with print() statements to sort out the issue.
Also, if you look at all of the Hint code sections in the notebook, they give you the entire solution. There are a lot of places for bad indentation and misplaced parenthesis.
Don’t worry about the later assert from unit test in test_cofi_cost_func() until you fix the built-in test.
When I change from the unregularized J += to the regularized J +=, should I still get 13.67 for lambda_ = 0? I don’t get 13.67 when I run the regularized line of code.
The equation for J += under the regularization details hint is accurate such that if I replace the unregularized line in the script with the equation for regularized J +=, I should get 13.6 for lambda_ = 0 and 28.09 for lambda_ = 1.5?
This statement confuses me.
You should not change your code specifically for either one.
Your code should be able to compute either, with the result due to the value of lambda.
That seems like the wrong approach.
I appreciate your patience, I normally don’t get tripped up like this however for some reason, I’m just not locking in on the approach. Based on your prior message, I understand how to compute either based on lambda. If I just focus on the regularization calculation where lambda = 1.5 for a moment, I should just be able to calculate the squares and sums of W and X, add those together, and multiply by lambda_/2, correct? The screenshot shows the matrices after each operation but I’m clearly not calculating something correctly.
I think you may have the wrong concept.
There are two parts of the cost value.
- The unregularized part. This is based on the errors in the predictions.
- The regularized part. This is based on the sums of the squares of the weights and features, multiplied by lambda.
The two parts are added together. That’s what the “J += …” part does.
So if lambda = 0, then the regularized part is zero. But you still always have to compute the unregularized part.
You are right, I certainly had the wrong concept. Adding the two parts together was what I was missing - somehow, I didn’t pick up on that during the recorded lecture. I do think the hints could be more clear but I did figure it based on your last reply - thanks for the assistance.
That’s good news.
The key in the notebook is the hint that first they calculate J, and then they calculate
J += <the regularized portion>.