IBCF is very similar to UBCF but with very minor changes in how we use the rating matrix.
The first step is to calculate the similarities between movies, as follows:
Since we have to calculate the similarity between movies, we use movie count as
k instead of user count:
k = ratings_train.shape neigh = NearestNeighbors(k,'cosine')
We fit the transpose of the rating matrix to the
Calculate the cosine similarity distance between each movie pair:
top_k_distances,top_k_users = neigh.kneighbors(ratings_train.T, return_distance=True) top_k_distances.shape (1682, 1682)
The next step is to predict the movie ratings using the following code:
item__pred = ratings_train.dot(top_k_distances) ...