Answers.Body: <p>You can use <strong>Collaborative Filtering</strong>, and specifically its <em>memory based approach</em>.</p>
  <p>The problem that you have discussed in the question should probably be solved using <em>user-item collaborative filtering</em>, which will calculate similarity between users and then recommend the item.</p>
  <p>The similarity can be be calculated using cosine similarity or Pearson's similarity formulae.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-14T08:56:08.033Z
Answers.LastActivityDate: 2024-12-20T14:18:30.463Z
Answers.LastEditDate: 2024-12-20T14:18:30.463Z
Answers.UserDisplayName: Neha Chaudhary
Body: <p>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.</p>
  <p>Say I have a list of of samples:</p>
  <pre><code>$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']
  ];
  </code></pre>
  <p>And we will say each array in the sample list is unique user's food preferences.</p>
  <p>Let's say now I have a user with this food preference:</p>
  <pre><code>['hot dog', 'mcchicken']
  </code></pre>
  <p>I want to be able to recommend to this user other foods that other users have in their preferences.</p>
  <p>So in the simplest terms, it should return:</p>
  <pre><code>['whopper', 'big mac', 'original chicken sandwich', 'mcrib', 'mcnuggets']
  </code></pre>
  <p>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.</p>
  <p>But I would like to find the best algorithm to start working on it.</p>
  <p>At first I thought <code>Apriori</code> might be my best guess, but I wasn't having luck once I introduced multiple items.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-13T21:18:44.047Z
Comments.Text: Why is "mcnuggets" not included in the output? I thought it should because one person likes ```['whopper', 'mcnuggets', 'mcchicken']```.
Comments.UserDisplayName: Varun Vejalla
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-13T21:51:27.293Z
Comments.Text: @VarunVejalla sorry I missed that. You're right, `mcnuggets` should also be included.
Comments.UserDisplayName: zen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-13T21:53:17.303Z
Comments.Text: 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.
Comments.UserDisplayName: Varun Vejalla
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-14T16:19:10.937Z
Comments.Text: @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.
Comments.UserDisplayName: zen
Tags: <machine-learning><algorithm-request><recommender-system>
Title: What is the most appropriate ML algorithm for creating recommendations
UserDisplayName: zen
ThreadText: # What is the most appropriate ML algorithm for creating recommendations
  
  (Asked by: username_0 on 2020-08-13)
  
  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.
  
  **Tags:** machine-learning, algorithm-request, recommender-system
  
  > **Comments:**
  > **username_1**: Why is "mcnuggets" not included in the output? I thought it should because one person likes ```['whopper', 'mcnuggets', 'mcchicken']```.  
  > **username_0**: @username_1 sorry I missed that. You're right, `mcnuggets` should also be included.  
  > **username_1**: 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.  
  > **username_0**: @username_1 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-08-14. Score: 3 | Accepted answer
  
  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.
  
  
  ---
  
  