views:

904

answers:

6

How to build a simple recommendation system? I have seen some algorithms but it is so difficult to implement I wish their is practical description to implement the most simple algorithm?

i have these three tables

        Users
  userid      username
   1            aaa
   2            bbb

and

        products
  productid        productname
     1                laptop
     2                mobile phone
     3                car

and

      users_products
  userid        productid
    1                1
    1                3
    3                2
    2                3

so I want to be able recommend items for each of the users depending on the items they purchased and other users' items

I knew it should something like calculating the similarites between users and then see their prosucts but how can be this done and stored in a database because this will require a table with something like this

      1    2   3   4   5   6 << users' ids
 1)   1   .4  .2  .3  .8  .4
 2)  .3    1  .5  .7  .3  .9
 3)  .4   .4   1  .8  .2  .3
 4)  .6   .6  .6   1  .4  .2
 5)  .8   .7  .4  .2   1  .3
 6)   1   .4  .6  .7  .9   1
 ^
 ^
users'
 ids

so how can similarty beween users calculated? and how could this complex data stored in ad database? (it requires a table with column for every user)? thanks

A: 

The table can be stored in three columns

user_left user_top correlation

(I have no experience with determining correlation, though)

peterchen
+5  A: 

How you want to actually store the recommendations is as a question completely unrelated to how one would actually implement a recommendation engine. I leave that to your database architecture. On to the recommending.

You said "simple", so a Pearson correlation coefficient might be the thing you need to read up on.

Calculating such a thing is dead simple. Concept, example code.

JosefAssad
Chris S
@JosefAssad- Thanks man and the example code was helpful, and now I am trying to apply this on my database but it seems difficult because I need get each record from the database and apply the algorithm and then store the results into a database table,thanks
ahmed
@Chris- if I am not mistaking (x= a list user 1 choices)(y = a list of user 2 choices)(then the result of the algorithm will be the similarities percentage between user 1 and user 2 choices), I guess :)
ahmed
A: 

You most certainly do not need a column for each user. You need a correlation matrix, that is true, but an actual database table is unnecessary. Instead you can imiplement it as

table: user_correlation_matrix
columns: user1_id user2_id correlation_factor
George Mauer
+1  A: 

Maybe reading "Programming Collective Intelligence" will help you.

duffymo
A: 

I saw this in one of Joe Celko's books. I believe it's this one Here. I don't have access to mine at the moment. Try heading over to a near by Barnes & Noble or Borders and check it out. I'll dig mine as soon as I have access and follow up.

Saif Khan
A: 

Use Taste.