new RecommenderSys([arg])

Recommender System

Example

// import analytics and la modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a Recommender System object
var recSys = new analytics.RecommenderSys({ tol: 1e-3, iter: 10000, k: 2, verbose: false });
// create the matrix to be fitted
var X = new la.Matrix([[1, 2, 1], [1, 1, 3]]);
// create the model
recSys.fit(X);

Parameter

Name Type Optional Description

arg

(module:analytics~RecSysParam or module:fs.FIn)

Yes

Construction arguments. There are two ways of constructing:
1. Using the module:analytics~RecSysParam object,
2. using the file input stream module:fs.FIn.

Methods

fit(A) → module:analytics.RecommenderSys

Fits the input matrix to the recommender model.

Examples

Asynhronous function

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new Recommender System object
var recSys = new analytics.RecommenderSys({ iter: 1000, k: 2 });
// create a matrix to be fitted
var X = new la.Matrix([[1, 5, 0], [1, 0, 3]]);
// create the model with the matrix X
recSys.fitAsync(X, function (err) {
   if (err) { console.log(err); }
   // successful calculation
});

Synhronous function

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new Recommender System object
var recSys = new analytics.RecommenderSys({ iter: 1000, k: 2 });
// create a matrix to be fitted
var X = new la.Matrix([[1, 5, 0], [1, 0, 3]]);
// create the model with the matrix X
recSys.fit(X);

Parameter

Name Type Optional Description

A

(module:la.Matrix or module:la.SparseMatrix)

 

Matrix with the ratings, where it A_ij element is the rating that the i-th person gave to the j-th item. If A_ij = 0, the data doesn't exist.

Returns

module:analytics.RecommenderSys Self. The model has been fitted.

getModel() → Object

Gets the model.

Example

// import modules
//var analytics = require('qminer').analytics;
//var la = require('qminer').la;
// create a new Recommender System object
//var recSys = new analytics.RecommenderSys({ iter: 1000, k: 3 });
// create a matrix to be fitted
//var X = new la.Matrix([[1, 5, 0], [1, 0, 3]]);
// create the model with the matrix X
//recSys.fit(X);
// get the model
//var model = recSys.getModel();
Returns

Object An object recSysModel containing the properties:
1. recSysModel.U - The matrix U from the weighted NMF. Type module:la.Matrix.
2. recSysModel.V - The matrix V from the weighted NMF. Type module:la.Matrix.

getParams() → module:analytics~RecSysParam

Returns the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new KMeans object
var recSys = new analytics.RecommenderSys({ iter: 1000, k: 5 });
// get the parameters
var json = recSys.getParams();
Returns

module:analytics~RecSysParam The construction parameters.

save(fout) → module:fs.FOut

Saves RecommenderSys internal state into (binary) file.

Example

// import modules
var analytics = require('qminer').analytics;
var fs = require('qminer').fs;
// create a new Recommender System object
var recSys = new analytics.RecommenderSys();
// change the parameters of the Recommender System object
recSys.setParams({ iter: 1000, k: 5 });
// create the file output stream
var fout = new fs.openWrite('recsys.bin');
// save the RecommenderSys instance
recSys.save(fout);
fout.close();
// load the RecommenderSys instance
var fin = fs.openRead('recsys.bin');
var recSys2 = new analytics.RecommenderSys(fin);

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

The output stream.

Returns

module:fs.FOut The output stream fout.

setParams(params) → module:analytics.RecommenderSys

Sets the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new Recommender System object
var recSys = new analytics.RecommenderSys();
// change the parameters of the Recommender System object
recSys.setParams({ iter: 1000, k: 5 });

Parameter

Name Type Optional Description

params

module:analytics~RecSysParam

 

The construction parameters.

Returns

module:analytics.RecommenderSys Self. The parameters has been updated.