Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago