Finding similarly liked movies
Just like you calculated the similarity between two movies, you can calculate it across all users to find the most similar movie to another based on how users have rated them.
The approach is similar to how you worked with content-based filtering.
You will find the similarity scores between all movies and then drill down on the movie of interest by isolating and sorting the column containing its similarity scores.
movie_ratings_centered
has once again been loaded, containing each movie as a row, and their centered ratings stored as the values.
Cet exercice fait partie du cours
Building Recommendation Engines in Python
Instructions
- Calculate the similarity matrix between all movies in
movie_ratings_centered
and store it as similarities. - Wrap the
similarities
matrix in a DataFrame, with the indices ofmovie_ratings_centered
as the columns and rows.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
from sklearn.metrics.pairwise import cosine_similarity
# Generate the similarity matrix
similarities = ____(____)
# Wrap the similarities in a DataFrame
cosine_similarity_df = ____.____(____, index=____.____, columns=____.____)
# Find the similarity values for a specific movie
cosine_similarity_series = cosine_similarity_df.loc['Star Wars: Episode IV - A New Hope (1977)']
# Sort these values highest to lowest
ordered_similarities = cosine_similarity_series.sort_values(ascending=False)
print(ordered_similarities)