Things You Should Know | Recommender Algorithm

We’ve already completed the bigger chunk of the recommender system. Now let’s finalize the algorithm.

There are three choices when it comes to recommendation algorithms, and it ties back to data:

1.     Collaborative filtering is a technique that relies on user interactions and feedback to recommend movies. This method suggests movies based on the behavior of other users who share similar tastes or preferences. This what Amazon uses to say “People like you also bought:”

2.     Content-based filtering, on the other hand, is a technique that recommends movies based on the features or characteristics of the movies themselves. For example, if a user has rated movies with certain genres or actors, the system will recommend movies with similar genres or actors.

3.     Hybrid: This is a model that takes into account both user’s interaction with the product, and how other people with similar preferences have rated the movies.

Our choice of algorithm is purely content-based filtering, as our dataset does not have enough information about the users to infer similarity between them.

We will create a recommendation algorithm that takes a movie (let’s say ‘Jumanji’), the similarity scores, and all the movies. From there, we will find top 10 movies that are closest similar to Jumanji and return them as recommendation. We will use basic pandas knowledge to filter out the results.

def get_recommendations(title, similarity=similarity,movies=movies):  

idx = movies[movies['title'] == title].index[0]  

movie_scores = list(enumerate(similarity[idx]))  

sorted_scores = sorted(movie_scores, key=lambda x: x[1], reverse=True)  

top_scores = sorted_scores[1:11]  

movie_indices = [i[0] for i in top_scores]  

return movies['title'].iloc[movie_indices]

Now you’ve created a movie recommender. Let’s test it out!

Call the function with the title of the movie, and you’ll get top 10 most similar movies to your chosen movie.

Top 10 similar movies to Jumanji are:

If you like an extra challenge, build a movie title generator, and use its output to get 10 top recommendations!

Let's check your understanding before we move to the final step.

Let's Continue