Week 2 - Lab 1: Collaborative Filtering Recommender Systems

I am trying to complete this assignment but I am hitting an error while running the tests for the cost function implementation checks.


While the previous tests returned the correct data I am hitting an error that doesn’t seem related to the results computed by my code, but mostly to how I implemented it (or so it seems).
To run the computations only on the films rated by the users I have used Numpy’s array masking (e.g. valid_data = np.ma.masked_where(R == 0, Y)). I am wondering if that breaks something in the tests somehow.
If that’s the case I’ll change my implementation.

Ok, I found what was the issue.
In one test case only the regularization part was valid as there were no user reviews, so the sum of the masked matrix returned nan instead of 0.0

1 Like

Great work resolving it yourself, Michele @Jazzinghen!

Raymond

Hello,
Thank you for initiating this question. I received same error. Still figuring out how to fix it. Any help will be appreciated

@Arshad_alam, have you figured out your issue?

If not, a few suggestions for debugging:

If it is the same error as shown in @Jazzinghen’s screenshot: a Typeerror when calling assert not(np.isclose(J, 13.5)), then you know that there is a problem with the type of J, which is the result from your cofi_cost_func() for this test case. In @Jazzinghen’s case, they said this was due to their code returning nan instead of 0.0 when there were no user reviews.

You can look at the specific test cases by going to the File/Open… menu in the Jupyter notebook and opening public_test.py and looking at the test_cofi_cost_func() function. This should show you which test is failing.

If you need to narrow it down further to see why this test case is failing in your code, you can temporarily add some print statements in your cofi_cost_func() to isolate where things are going wrong and causing it to return something that is not a valid number.

1 Like