C3_W2_Collaborative_RecSys_Assignment Help


NameError Traceback (most recent call last)
in
11
12 # Evaluate cost function
—> 13 J = cofi_cost_func(X_r, W_r, b_r, Y_r, R_r, 0);
14 print(f"Cost: {J:0.2f}")

in cofi_cost_func(X, W, b, Y, R, lambda_)
31 J += (np.dot(w, x) + b_j - y) ** 2
32
—> 33 J = J / (2 * num_ratings)
34 reg_term = (lambda_ / 2) * (np.sum(W ** 2) + np.sum(X ** 2)) # Remove the b term from regularization
35 J += reg_term

NameError: name ‘num_ratings’ is not defined

The error says there is no such variable num_ratings defined in your function.

I had to restart the lab, there was some issue and it wasn;t identifying any of my functions

Also, note that you are dividing the cost by num_ratings, which is incorrect.