Han Wang
Han Wang

Reputation: 89

Similarities based friend recommendation algorithm

I'm trying to build a friend recommendation algorithm that recommends users a new friend every week. Let's say I have a database of

user A
user B
user C
...

and they have a list of hobbies

user A has interests [hobby1, hobby2, hobby3, etc...]
user B has interests [hobby3, hobby6, hobby8, etc...]
user C has interests [hobby1, hobby3, hobby4, etc...]
...

How do I build an algorithm that pairs pick a good recommendation for everyone with the catch that it should be different every week?

Week 1

user A -> user C [2 hobbies in common]
user B -> user A [1 hobby in common]
user C -> user B [1 hobby in common]
...

Week 2

user A -> user B [1 hobby in common]
user B -> user C [1 hobby in common]
user C -> user A [2 hobbies in common]
...

Because on the requirements, it sounds like it could be easy to just completely randomize all user recommendations every week. Is there anything that would be better than that threshold?

Upvotes: 1

Views: 254

Answers (1)

Lucas Charbonnier
Lucas Charbonnier

Reputation: 461

First, you need a function that takes 2 Users (A and B) and outputs a "similarity score". The simplest way to do that is to count the amount of common hobbies. Then find the user that has the best "similarity score" with A and recommend it to A.
Keep a table containing all recommendation (let's call it t_recommendations) that have been made to a certain person, this way, the next time you need to recommend a new person to A, take the person with the highest "similarity score" that is not in t_recommendations.

Table t_recommendations would have the following columns :

  • recommended_to : The ID of the user that received a recommendation
  • recommended : The ID of the user that has been recommended to recommended_to
  • recommendation_date: This one is optional but could be useful if you want to start recommending people again after a while.

Upvotes: 1

Related Questions