Properties

new RecLinReg(arg)

Recursive Linear Regression

Example

// import analytics module
var analytics = require('qminer').analytics;
// create the recursive linear regression model holder
var linreg = new analytics.RecLinReg({ dim: 10, regFact: 1.0, forgetFact: 1.0 });

Parameter

Name Type Optional Description

arg

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

 

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

Properties

dim

Gets the dimensionality of the model. Type number.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 10 });
// get the dimensionality of the model
var dim = linreg.dim;

weights

Gives the weights of the model. Type module:la.Vector.

Example

// import analytics module
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 2 });
// create a new dense matrix and target vector
var mat = new la.Matrix([[1, 2], [1, -1]]);
var vec = new la.Vector([3, 3]);
// fit the model with the matrix
linreg.fit(mat, vec);
// get the weights of the model
var weights = linreg.weights;

Methods

fit(mat, vec) → module:analytics.RecLinReg

Creates/updates the internal model.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 2.0 });
// create a new dense matrix and target vector
var mat = new la.Matrix([[1, 2, 3], [3, 4, 5]]);
var vec = new la.Vector([3, 5, -1]);
// fit the model with the matrix
linreg.fit(mat, vec);

Parameters

Name Type Optional Description

mat

module:la.Matrix

 

The input matrix.

vec

module:la.Vector

 

The target numbers, where the i-th number in vector is the target number for the i-th column of the mat.

Returns

module:analytics.RecLinRegB Self. The internal model is updated.

getModel() → Object

Gets the model.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create the Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 10 });
// get the model
var model = linreg.getModel(); // returns { weights: new require('qminer').la.Vector(); }
Returns

ObjectB The recLinRegModel object containing the property:
1. recLinRegModel.weights - The weights of the model. Type module:la.Vector.

getParams() → module:analytics~recLinRegParam

Returns the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 10 });
// get the parameters of the model
var params = linreg.getParams(); // returns { dim: 10, recFact: 1.0, forgetFact: 1.0 }
Returns

module:analytics~recLinRegParamB The parameters of the model.

partialFit(vec, num) → module:analytics.RecLinReg

Updates the internal model.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 3.0 });
// create a new dense vector
var vec = new la.Vector([1, 2, 3]);
// fit the model with the vector
linreg.partialFit(vec, 6);

Parameters

Name Type Optional Description

vec

module:la.Vector

 

The input vector.

num

number

 

The target number for the vector.

Returns

module:analytics.RecLinRegB Self. The internal model is updated.

predict(vec) → number

Puts the vector through the model and returns the prediction as a real number.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create the Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 2.0, recFact: 1e-10 });
// create a new dense matrix and target vector
var mat = new la.Matrix([[1, 2], [1, -1]]);
var vec = new la.Vector([3, 3]);
// fit the model with the matrix
linreg.fit(mat, vec);
// create the vector to be predicted
var pred = new la.Vector([1, 1]);
// predict the value of the vector
var prediction = linreg.predict(pred); // returns something close to 3.0

Parameter

Name Type Optional Description

vec

module:la.Vector

 

The prediction vector.

Returns

numberB The prediction.

save(fout) → module:fs.FOut

Save model to provided output stream.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
var fs = require('qminer').fs;
// create the Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 2.0, recFact: 1e-10 });
// create a new dense matrix and target vector
var mat = new la.Matrix([[1, 2], [1, -1]]);
var vec = new la.Vector([3, 3]);
// fit the model with the matrix
linreg.fit(mat, vec);
// create an output stream object and save the model
var fout = fs.openWrite('linreg_example.bin');
linreg.save(fout);
fout.close();
// create a new Nearest Neighbor Anomaly model by loading the model
var fin = fs.openRead('linreg_example.bin');
var linreg2 = new analytics.RecLinReg(fin);

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

The output stream.

Returns

module:fs.FOutB The output stream fout.

setParams(params) → module:analytics.RecLinReg

Sets the parameters of the model.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 10 });
// set the parameters of the model
linreg.setParams({ dim: 3, recFact: 1e2, forgetFact: 0.5 });

Parameter

Name Type Optional Description

params

module:analytics~recLinRegParam

 

The new parameters of the model.

Returns

module:analytics.RecLinRegB Self. The parameters are updated. Any previous model is set to default.