This is a technique used in recommendations systems to predict preferences of a user by collecting preferences from many users.

There are 2 types:

  1. user based collaborative filtering - finds users who are similar to the target user based on their past interactions (e.g., ratings or purchases) and recommends items that these similar users liked
  2. item based collaborative filtering - looks at the similarity between items based on users’ past behavior. It recommends items that are similar to what the target user has liked in the past

Here is code. Its scrollable :)

https://gist.github.com/bmwasaru/de9572f5c129f85ccdf7a9c7e4dcead8

You can find the Jupyter notebook here https://github.com/bmwasaru/collaborative_filtering/blob/main/collaborative_filtering.ipynb

Leave me a comment, I like feedback :)