From the course: Building Recommender Systems with Machine Learning and AI

Unlock this course with a free trial

Join today to access over 22,700 courses taught by industry experts.

Item-based collaborative filtering: Hands-on

Item-based collaborative filtering: Hands-on - Python Tutorial

From the course: Building Recommender Systems with Machine Learning and AI

Item-based collaborative filtering: Hands-on

- [Instructor] So let's play around with item-based collaborative filtering. Open Spyder back up and take a look at SimpleItemCF.py. As you might expect, it looks a lot like SimpleUserCF.py, because the general approach is the same as user-based collaborative filtering. We're just focusing on relationships between items instead of users. The first difference you'll see is that, when we set up these sim options, we're passing false for user-based. This tells the surprise library to generate an item-to-item similarity matrix using cosine as its similarity metric instead of a user-to-user similarity matrix. Next, we pull off the top K highest-rated items for our test user, then we look up all of the items similar to each of those items. These become our recommendation candidates, and as we build up our list of candidates, we score them by their similarity score to the item our user rated and by the rating our user gave that item. The rest of the code is the same. We build up a dictionary…

Contents