I am trying to find the best algorithm to create a list of recommendations for a user based on the interests of all other users.

Say I have a list of of samples:

$samples = [
    ['hot dog', 'big mac', 'whopper'],
    ['hot dog', 'big mac'],
    ['hot dog', 'whopper'],
    ['big mac', 'dave single'],
    ['whopper', 'mcnuggets', 'mcchicken'],
    ['mcchicken', 'original chicken sandwich'],
    ['mcchicken', 'mcrib']

And we will say each array in the sample list is unique user's food preferences.

Let's say now I have a user with this food preference:

['hot dog', 'mcchicken']

I want to be able to recommend to this user other foods that other users have in their preferences.

So in the simplest terms, it should return:

['whopper', 'big mac', 'original chicken sandwich', 'mcrib', 'mcnuggets']

Obviously I will also introduce other variables such as how each user rates each item in their preference list and also the percentage of users that need to have that item in order to use their other food items as recommendations.

But I would like to find the best algorithm to start working on it.

At first I thought Apriori might be my best guess, but I wasn't having luck once I introduced multiple items.

  • $\begingroup$ Why is "mcnuggets" not included in the output? I thought it should because one person likes ['whopper', 'mcnuggets', 'mcchicken']. $\endgroup$ Aug 13, 2020 at 21:18
  • $\begingroup$ @VarunVejalla sorry I missed that. You're right, mcnuggets should also be included. $\endgroup$
    – zen
    Aug 13, 2020 at 21:51
  • $\begingroup$ In that case, I don't think a machine learning approach is needed. Simply loop through all the samples. If there is a common element between the sample and the test user, add all elements in the sample (except for those already preferred by the user) to the recommendations. $\endgroup$ Aug 13, 2020 at 21:53
  • $\begingroup$ @VarunVejalla yes I've thought about that before but I do not want it to be that simple. I was just giving a simple usage case as an example. I'd want to later introduce other variables to the equation i.e. how much each user rates such items, how much each items are priced, what categories each items belong in, etc... It can all be done manually using various logic, but I was hoping there was a ML way to do it smarter so I'm not looping through millions of items each time. $\endgroup$
    – zen
    Aug 14, 2020 at 16:19

1 Answer 1


You can use Collaborative Filtering, and specifically its memory based approach. The problem that you have discussed in the question should probably be solved using User-Item collaborative filtering which will calculate similarity between users and then recommend the item. The similarity can be be calculated using cosine similarity or Pearson's similarity formulae.

The best thing about this approach is that no training is required here but if you wish to have very large data, this approach's performance decreases.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .