I encountered a problem while working on Exercise 1 of the C3_W2_Collaborative_RecSys_Assignment, but I managed to figure it out. I wanted to share my solution with you.

In the assignment, we were asked to implement the cost function for collaborative filtering with regularization. I initially had some issues with my code, but after reviewing the hints, I made the necessary modifications.

Here’s the updated code for the cofi_cost_func function:

pythonCopy code

def cofi_cost_func(X, W, b, Y, R, lambda_):
nm, nu = Y.shape
J = 0
# moderator edit: code removed - not allowed
return J

In this updated code, I have added the regularization term to the cost function calculation using the formula moderator edit - code removed. This helps prevent overfitting and improves the accuracy of the collaborative filtering model.

After making these modifications, the code produced the correct results for the provided test cases. However, I noticed that there were some discrepancies in the expected outputs mentioned in the comments. The correct output values for the test cases should be as follows:

For the “Evaluate cost function with regularization” test: Expected output is 28, which matches the calculated result.

For the “Public tests” case: The expected output is 27, but the provided code does not seem to account for regularization correctly. I suspect that the expected output might be incorrect in this case.

I am struggling with the reconciliation effort with the expected output too. I get 28.5 for the “Evaluate cost with regularization” test and 54 for the “public tests” case. Can certainly use some guidance to wrap this practice lab up.

The expected value for the regularized test (to two decimal places) is 28.09. Your answer will have additional digits, but they’re not really significant for the purposes of this test.

The “public tests” actually contain five different tests - only one of them gives the result 27.0.

Note: I’m going to delete the code from your post, since sharing your code on the forum for a graded assignment is not allowed by the Code of Conduct.