C3_W2_Collaborative_RecSys_Assignment

AssertionError Traceback (most recent call last)
in
1 # Public tests
2 from public_tests import *
----> 3 test_cofi_cost_func(cofi_cost_func)

~/work/public_tests.py in test_cofi_cost_func(target)
14 J = target(X_r, W_r, b_r, Y_r, R_r, 2);
15 assert not np.isclose(J, 13.5), f"Wrong value. Got {J}. Did you multiplied the regulartization term by lambda_?"
β€”> 16 assert np.isclose(J, 27), f"Wrong value. Expected {27}, got {J}. Check the regularization term"
17
18

AssertionError: Wrong value. Expected 27, got 270.0. Check the regularization term

1 Like

Hi!

Can you send me your code in a direct message so I can help?

1 Like

Yes, the code is sent to you directly along with it’s screenshot!
Waiting for the solution!

Hi I got the same issue. Have you found any solution?

Hi @Yoko0618 !

Can you send me your code in a direct message so I can help?

I got this error while implementing even before regularisation. Can anyone point to the mistake?

AssertionError Traceback (most recent call last)
in
1 # Public tests
2 from public_tests import *
----> 3 test_cofi_cost_func(cofi_cost_func)

~/work/public_tests.py in test_cofi_cost_func(target)
14 J = target(X_r, W_r, b_r, Y_r, R_r, 2);
15 assert not np.isclose(J, 13.5), f"Wrong value. Got {J}. Did you multiplied the regulartization term by lambda_?"
β€”> 16 assert np.isclose(J, 27), f"Wrong value. Expected {27}, got {J}. Check the regularization term"
17
18

AssertionError: Wrong value. Expected 27, got 0.0. Check the regularization term

Hi!

Can you send me your code in a direct message so I can help?

def cofi_cost_func(X, W, b, Y, R, lambda_):
β€œβ€"
Returns the cost for the content-based filtering
Args:
X (ndarray (num_movies,num_features)): matrix of item features
W (ndarray (num_users,num_features)) : matrix of user parameters
b (ndarray (1, num_users) : vector of user parameters
Y (ndarray (num_movies,num_users) : matrix of user ratings of movies
R (ndarray (num_movies,num_users) : matrix, where R(i, j) = 1 if the i-th movies was rated by the j-th user
lambda_ (float): regularization parameter
Returns:
J (float) : Cost
β€œβ€"
nm, nu = Y.shape
J = 0
### START CODE HERE ###
for j in range(nu):
w = W[j,:]
b_j = b[0,j]
for i in range(nm):
x = X[i,:]
y = Y[i,j]
r = R[i,j]
J += np.square(r * (np.dot(w,x) + b_j - y ) )
J = J/2
### END CODE HERE ###

return J