Format error in collaborative filtering assignment

Hi hope you all well . I am trying to evaluate my cost function but I am facing error below:
“TypeError: unsupported format string passed to NoneType.format
here is the full code:

{code removed by mentor}

# Reduce the data set size so that this runs faster
num_users_r = 4
num_movies_r = 5 
num_features_r = 3

X_r = X[:num_movies_r, :num_features_r]
W_r = W[:num_users_r,  :num_features_r]
b_r = b[0, :num_users_r].reshape(1,-1)
Y_r = Y[:num_movies_r, :num_users_r]
R_r = R[:num_movies_r, :num_users_r]

# Evaluate cost function
J = cofi_cost_func(X_r, W_r, b_r, Y_r, R_r, 0);
print(f"Cost: {J:0.2f}")

HI @Oktay_vosoughi

There are one error here is in the for loop you didn’t want to divide j(cost) with half but you should divide total cost by half before the return like what you had done… like this equation
also please make sure from the indentation of you code and you can also check the hint
Note the sharing of code is not allowed here


Please also note that the error message you have got indicates that your function returned a None object which is wrong to do so. Please read the DocString for what you need to return:

# GRADED FUNCTION: cofi_cost_func
# UNQ_C1

def cofi_cost_func(X, W, b, Y, R, lambda_):
    Returns the cost for the content-based filtering
      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
      J (float) : Cost
    nm, nu = Y.shape
    J = 0
    ### START CODE HERE ###  
    ### END CODE HERE ### 

    return J


PS: I am removing your code as explained by @AbdElRhaman_Fakhry. Next time, please just share a screenshot of the full error traceback.

thanks Reymond for your response. after putting the massage I got my error but I couldn’t remove it.

Hello @Oktay_vosoughi,

Do you mean you are encountering an error? If so, please share the error traceback with us, so that our mentors can give you some suggestions. Please don’t post your code though.

Happy new year, and cheers,