QMiner recommendation

node v0.12.18
version: 2.0.0
endpointsharetweet
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'); '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' }], joins: [{ name: 'lectures', type: 'index', store: 'Lectures', inverse : 'visitors' }] }, { name: 'Lectures', fields: [{ name: 'Title', type: 'string' }], joins: [{ name: 'visitors', type: 'index', store: 'Visitors', inverse: 'lectures'}] }] }); 'defined schema'
Import visit data.
visitors.loadJson('visits.json', 1000); 'Loaded' + visitors.length + 'visitors and' + lectures.length + 'lectures'
Check what we know for one visitor. Let us call him John.
var john = base.store('Visitors')[id]; john.ID + ' viewed ' + john.lectures.length + ' lectures'
We can list all the lectures viewed by John by following 'lectures' join.
john.lectures.each(function (l) { console.log(' -', l.Title); });
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 = visitor.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(visitor.lectures); result.sortByFq(-1).trunc(5);
Let's list the recommendations!
result.each(function (l) { console.log(' -', l.Title); });
Loading…

no comments

    sign in to comment