Question: def predict _ from _ sim ( self , uid,mid ) : Predict a user rating on a movie given userID and

def predict_from_sim(self,uid,mid):
"""
Predict a user rating on a movie given userID and movieID
"""
# Predict user rating as follows:
# 1. Get entry of user id in rating matrix
# 2. Get entry of movie id in sim matrix
# 3. Employ 1 and 2 to predict user rating of the movie
# your code here
user_idx = self.uid2idx[uid]
movie_idx = self.mid2idx[mid]
sim_ratings = self.Mr[user_idx]* self.sim[movie_idx]
# print(sim_ratings[sim_ratings >0])
sim_sum = np.sum(self.sim[movie_idx])
return np.sum(sim_ratings)/(sim_sum if sim_sum !=0 else 0)
# Sample tests for predict_from_sim in RecSys class
assert(sample_cb.predict_from_sim(245,276)==approx(2.5128205128205128,abs=1e-2)), "Check predict_from_sim. Look at how you predicted a user rating on a movie given UserID and movieID."
assert(sample_cb.predict_from_sim(2026,2436)==approx(2.785714285714286,abs=1e-2)), "Check predict_from_sim. Look at how you predicted a user rating on a movie given UserID and movieID."
Error Message:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
in
3
4 # Sample tests for predict_from_sim in RecSys class
---->5 assert(sample_cb.predict_from_sim(245,276)==approx(2.5128205128205128,abs=1e-2)), "Check predict_from_sim. Look at how you predicted a user rating on a movie given UserID and movieID."
6 assert(sample_cb.predict_from_sim(2026,2436)==approx(2.785714285714286,abs=1e-2)), "Check predict_from_sim. Look at how you predicted a user rating on a movie given UserID and movieID."
AssertionError: Check predict_from_sim. Look at how you predicted a user rating on a movie given UserID and movieID.

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 Databases Questions!