Question: IndexError Traceback ( most recent call last ) in ( ) 1 1 1 2 # Evaluate cost function - - - > 1 3

IndexError Traceback (most recent call last)
in ()1112 # 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_)26 for i in range(num_movies): 27 for j in range(num_users): --->28 if R[i, j]==1: 29 J+=(np.dot(X[j, :], Theta[i, :])- Y[i, j])**230
IndexError: index 4 is out of bounds for axis 1 with size 4
here is my code
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}")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!