Collborative filtering assignment - need help

This is for week #2 assignment ( Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera )

The code I’ve written passes all the tests except for the last one. The error message is “Wrong value. Expected 13.621929978531858, got 12.672019395081678.”

The regularization term values I’ve computed are 8.015224040196546 for X and 4.414542034361463 for W. The sum of all the losses is 0.24225332052366916 so the final cost ends up being less that 13.6

Which test are you running? Please post a screen capture image.

Be careful how you’re handling the scaling of the regularized part of the cost by the lambda_ value. It’s easy to mess this up with incorrect parenthesis.

Sure, here is a screenshot of the error

The instructions for implementing cofi_cost_func says " Note that you should be accumulating the cost for user j and movie i only if R(i,j) = 1.". Which I implemented but when I remove that condition ( if R[i,j] != 1 : break ) from the last loop it passes all the tests now.

‘break’ probably isn’t the correct method.

Since the R values are 0 or 1, you can instead use an element-wise matrix product, and avoid using a for-loop entirely.

Just following the instructions to implement a for loop. Do you know why the instruction says to only consider if R[i,j] = 1 when doing so causes the function to fail one of the test ?

Because if you do it correctly, that’s exactly how it should work.

I suspect there is a flaw in your implementation that is giving you an error message which is difficult to interpret.