QMiner recommendation

node v0.12.18
version: 8.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', 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(base.store('Visitors')); 'Loaded ' + base.store('Visitors').length + ' visitors'
'Loaded ' + base.store('Lectures').length + ' lectures'
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 = base.store('Visitors')[126]; 'Visitor ' + john.ID + ' viewed ' + john.lectures.length + ' lectures'
john.lectures[0].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 = john.lectures.join('visitors'); coVisitors.length + ' visitors watched the same lecture'
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[0].Title
result[1].Title
result[2].Title
result[3].Title
result[4].Title
Loading…

no comments

    sign in to comment