Question: Q 3 . Collaborative Filtering 3 a . Complete the function cossim in the class Collaborative [ 1 0 pts ] To Do: 1 .

Q3. Collaborative Filtering
3a. Complete the function cossim in the class Collaborative [10 pts]
To Do:
1.Impute the unrated entries in self.Mr to the user's average rating then subtract by the user mean, call this matrix X.
2.Calculate cosine similarity for all item-item pairs. Don't forget to rescale the cosine similarity to be 0~1.
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 0=[0,0,0,....,0]. 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 =0? What about when =0 and is an any vector?
Hint: You may use scipy.spatial.distance.cosine, but it will be slow because its cosine function does vector-vector operation whereas you can implement matrix-matrix operation using numpy to calculate all cosines all at once (it can be 100 times faster than vector-vector 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 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!