0

I am trying to find similarity between the new users and the existing ones(generated a trained model from recommend method of graphlab) from trained model. So, tried using nearest neighbor similarity method(query option) in graphalb to do in this way. //data is the dataset containing 100 users and their items-ratings

model = graphlab.nearest_neighbors.create(data)
qry=graphlab.SFrame({'UserId':[101,101,101,101,101,101,101,101,101,101,101],
                'ItemId':["activity1","activity2","activity3","activity4","activity5","activity6","activity7","activity8","activity9","activity10","activity11"],
                'Rating':[3,9,8,5,7,4,8,6,6,3,7]})
 qry.swap_columns('UserId','ItemId')
 qry.swap_columns('ItemId','Rating')
 qry.print_rows()
 kn=model.query(qry)

Basically,I am passing the new userId's(101) data in query method, the itemIds and corresponding ratings of those activities. These itemIds and ratings are nothing but actually an existing user's items-ratings that I am passing to new user,so as to check for similarity if the new user is similar to the existing one.

The output that is expected from using query() is that it should return an SFrame with four columns: query label, reference label, distance, and rank of the reference point among the query point's nearest neighbors(as per Graphlab documentation). But I am getting something like this-

| Query points | # Pairs | % Complete. | Elapsed Time |

| 0 | 11 | 0.0909091 | 624us | | Done | | 100 | 3.68ms |

Can anybody help as to why this isn't producing the correct output?

1 Answers1

0

GraphLab Create's nearest neighbors model expects each row to correspond to a user for both the reference and query data, so for query user 101, all of the ratings need to be "unstacked" into one row:

qry = qry.unstack(['ItemId', 'Rating'], new_column_name='Rating')

The column with the ratings does need to have the same name of the corresponding column in the reference data.

The other note is that the output you saw is just progress printing. To see the actual results, inspect the kn object:

print kn
papayawarrior
  • 1,027
  • 7
  • 10