class staticanalytics. RecLinReg
Source: analyticsdoc.
Holds the Recursive Linear Regression model.
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 |
|
Construction arguments. There are two ways of constructing:
|
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 |
|
The input matrix. |
|
vec |
|
The target numbers, where the i-th number in vector is the target number for the i-th column of the |
- Returns
-
module:analytics.RecLinReg
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
-
Object
TherecLinRegModel
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~recLinRegParam
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 |
|
The input vector. |
|
num |
number |
|
The target number for the vector. |
- Returns
-
module:analytics.RecLinReg
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 |
|
The prediction vector. |
- Returns
-
number
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 |
|
The output stream. |
- Returns
-
module:fs.FOut
The output streamfout
.
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 |
|
The new parameters of the model. |
- Returns
-
module:analytics.RecLinReg
Self. The parameters are updated. Any previous model is set to default.