Build a recommendation engine in 10 minutes using Recombee in Python

Original article was published by Chaudhry Talha on Artificial Intelligence on Medium


Now, we have finished two aspects the third and final part before we can get recommendations is to add interactions. In a real application we can add these snippets which will run when a particular action is taken.

Let’s add some interactions. For demonstration purpose we’ll take five users. So, let’s pick user with id 11, 13, 14, 15, 17 (Just picked randomly from the above screenshot).

Let’s assume the following user{id} and item{id}:
user11 has viewed item0, item104, item107 and rated item110.
user13 has viewed item109, item110, item0, item103, item101, item104.
user14 has viewed item10, item11 and purchased item115.
user15 has viewed item113, item111, item 105, item102.
user17 has viewed item140, item142, item15, item151, item144 and purchased item15.

Above are our 5 user cases where we have fetched data from user actions on our website. Now how we’ll add these interactions to our recombee engine:

#user11 has viewed item0, item104, item107 and rated item110.client.send(AddDetailView('11','0', cascade_create=True))
client.send(AddDetailView('11','104', cascade_create=True))
client.send(AddDetailView('11','107', cascade_create=True))
client.send(AddRating('11','110', 0.5, cascade_create=True))# Rating rescaled to interval [-1.0,1.0],
# where -1.0 means the worst rating possible, 0.0 means neutral, and 1.0 means absolutely positive rating.
# For example, in the case of 5-star evaluations, rating = (numStars-3)/2 formula may be used for the conversion.
# So here user rated 4/5 to a course (4-3)/2 = 0.5
#Also the rating here will have no effect on the rating of item110 that is available in the dataset.

And now the rest of the users:

#user13 has viewed item109, item110, item0, item103, item101, item104.
client.send(AddDetailView('13','109', cascade_create=True))
client.send(AddDetailView('13','110', cascade_create=True))
client.send(AddDetailView('13','0', cascade_create=True))
client.send(AddDetailView('13','103', cascade_create=True))
client.send(AddDetailView('13','101', cascade_create=True))
client.send(AddDetailView('13','104', cascade_create=True))
#user14 has viewed item10, item11 and purchased item115.
client.send(AddDetailView('14','10', cascade_create=True))
client.send(AddDetailView('14','111', cascade_create=True))
client.send(AddPurchase('14','115', cascade_create=True))
#user15 has viewed item113, item111, item 105, item102.
client.send(AddDetailView('15','113', cascade_create=True))
client.send(AddDetailView('15','111', cascade_create=True))
client.send(AddDetailView('15','105', cascade_create=True))
client.send(AddDetailView('15','102', cascade_create=True))
#user17 has viewed item140, item142, item15, item151, item144 and purchased item15.
client.send(AddDetailView('17','140', cascade_create=True))
client.send(AddDetailView('17','142', cascade_create=True))
client.send(AddDetailView('17','15', cascade_create=True))
client.send(AddDetailView('17','151', cascade_create=True))
client.send(AddDetailView('17','144', cascade_create=True))
client.send(AddPurchase('17','15', cascade_create=True))

You’ll get ok status after these interactions are successfully published. Also we’ve added the interactions one by one we could have also add it to a excel sheet and upload them using for loop but the reason for this is give you the idea that in an application when an action is occured you’ll send a recombee client request to update it accordingly

Now if you go back to the dashboard you can see some numbers other than all blanks.