Question: Q 3 . Collaborative Filtering 3 a . Complete the function cossim in the class Collaborative [ 1 0 pts ] To Do: 1 .
Q Collaborative Filtering
a Complete the function cossim in the class Collaborative pts
To Do:
Impute the unrated entries in self.Mr to the user's average rating then subtract by the user mean, call this matrix X
Calculate cosine similarity for all itemitem pairs. Don't forget to rescale the cosine similarity to be ~
You might encounter divide by zero warning numpy will fill nan value for that entry In that case, you can fill those with appropriate values.
Hint: Let's say a movie item has not been rated by anyone. When you calculate similarity of this vector to anoter, you will get When you normalize this vector, you'll get divide by zero warning and it will make nan value in self.sim matrix. Theoretically what should the similarity value for when What about when and is an any vector?
Hint: You may use scipy.spatial.distance.cosine, but it will be slow because its cosine function does vectorvector operation whereas you can implement matrixmatrix operation using numpy to calculate all cosines all at once it can be times faster than vectorvector operation in our data Also pay attention to the definition. The scipy.spatial.distance provides distance, not similarity.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
