Recommendation of items using "visitors that view this also viewed..." approach. That is, visitors are recommended items that are most often viewed by other visitors that watched some of the same items. In this example we will use visitor-item data from online lectures website VideoLectures.NET.
Import libraries: the main library qminer and a helper package for the example dataset.
var qm = require('qminer'); var loader = require('qminer-data-loader@1.1.0'); 'libraries loaded'
Define the storage schema. We have two stores: one for visitors descrbied by a unique ID and one for lectures described by their title. Visitors and lectures are connected by a join.
var base = new qm.Base({ mode: 'createClean', schema: [{ name: 'Visitors', fields: [{ name: 'ID', type: 'string', primary: true }], joins: [{ name: 'lectures', type: 'index', store: 'Lectures', inverse : 'visitors' }] }, { name: 'Lectures', fields: [{ name: 'Title', type: 'string', primary: true }], joins: [{ name: 'visitors', type: 'index', store: 'Visitors', inverse: 'lectures'}] }] }); 'defined schema'
Import visit data.
loader.loadRecommendationDataset('Visitors')); 'Loaded ' +'Visitors').length + ' visitors'
Check what we know for one visitor. Let us call him John. We see which lectures did John see by following 'lectures' join.
var john ='Visitors')[126]; 'Visitor ' + john.ID + ' viewed ' + john.lectures.length + ' lectures'
Now lets generate a list of lectures to recommend to john. First, let us see who else viewed the same lectures by following the 'visitors' join.
var coVisitors = john.lectures.join('visitors'); coVisitors.length + ' visitors watched at least one of the same lectures'
Then, lets see what else did the co-visitors viewed. In order to speed up recommendation process we use sampling to select only 100 visitors and check what they viewed. Sampling takes into account the weights, meaning that visitors that share more lectures with John are more likely to be selected.
var coLectures = coVisitors.join('lectures', 100); 'Co-visitors watched ' + coLectures.length + ' lectures'
Finally, removed the lectures already seen by John, sort the final result by frequency and keep top 5. In this scenario, frequencies correspond to number of co-visitors that viewed the lecture.
var result = coLectures.setDiff(john.lectures); result.sortByFq(-1).trunc(5); 'Recommendations generated'
Let's list the recommendations!
result.each(function (l) { console.log(l.Title); }); 'Done!'

no comments

    sign in to comment