analytics. RecommenderSys
Source: analyticsdoc.
The recommender system algorithm using Weighted Non-negative Matrix Factorization to predict the
unknown values. If A
is a matrix with unknown values it calculates the matrices U
and V
such that U*V
approximates A
.
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 |
Yes |
Construction arguments. There are two ways of constructing:
|
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 |
|
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
B 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
B An objectrecSysModel
containing the properties:
1.recSysModel.U
- The matrixU
from the weighted NMF. Type module:la.Matrix.
2.recSysModel.V
- The matrixV
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
B 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 |
|
The output stream. |
- Returns
-
module:fs.FOut
B The output streamfout
.
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 |
|
The construction parameters. |
- Returns
-
module:analytics.RecommenderSys
B Self. The parameters has been updated.