analytics. SVR
Source: analyticsdoc.
Support Vector Machine Regression. Implements a soft margin linear support vector regression using the PEGASOS algorithm with epsilon insensitive loss, see: Pegasos: Primal Estimated sub-GrAdient SOlver for SVM.
Property
new SVR([arg])
SVR
Example
// import module
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// REGRESSION WITH SVR
// Set up fake train and test data.
// Four training examples with, number of features = 2
var featureMatrix = new la.Matrix({ rows: 2, cols: 4, random: true });
// Regression targets for four examples
var targets = new la.Vector([1.1, -2, 3, 4.2]);
// Set up the regression model
var SVR = new analytics.SVR({ verbose: false });
// Train regression
SVR.fit(featureMatrix, targets);
// Set up a fake test vector
var test = new la.Vector([1.1, -0.8]);
// Predict the target value
var prediction = SVR.predict(test);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
arg |
Yes |
Construction arguments. There are two ways of constructing:
|
Property
weights
The vector of coefficients of the linear model. Type module:la.Vector.
Example
// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new SVR object
var SVR = new analytics.SVR({ c: 10 });
// create a matrix and vector for the model
var matrix = new la.Matrix([[1, -1], [1, 1]]);
var vector = new la.Vector([1, 1]);
// create the model by fitting the values
SVR.fit(matrix, vector);
// get the coeficients of the linear model
var coef = SVR.weights;
Methods
decisionFunction(X) → (number or module:la.Vector)
Sends vector through the model and returns the scalar product as a real number.
Example
// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new SVR object
var SVR = new analytics.SVR({ c: 10 });
// create a matrix and vector for the model
var matrix = new la.Matrix([[1, -1], [1, 1]]);
var vector = new la.Vector([1, 1]);
// create the model by fitting the values
SVR.fit(matrix, vector);
// get the distance between the model and the given vector
var vec2 = new la.Vector([-5, 1]);
var distance = SVR.decisionFunction(vec2);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
X |
(module:la.Vector, module:la.SparseVector, module:la.Matrix, or module:la.SparseMatrix) |
|
Input feature vector or matrix with feature vectors as columns. |
- Returns
-
(number or module:la.Vector)
B Distance:
1. Real number ifX
is module:la.Vector or module:la.SparseVector.
2. module:la.Vector, ifX
is module:la.Matrix or module:la.SparseMatrix.
fit(X, y) → module:analytics.SVR
Fits a SVM regression model, given column examples in a matrix and vector of targets.
Example
// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new SVR object
var SVR = new analytics.SVR({ c: 10 });
// create a matrix and vector for the model
var matrix = new la.Matrix([[1, -1], [1, 1]]);
var vector = new la.Vector([1, 1]);
// create the model by fitting the values
SVR.fit(matrix, vector);
Parameters
Name | Type | Optional | Description |
---|---|---|---|
X |
|
Input feature matrix where columns correspond to feature vectors. |
|
y |
|
Input vector of targets, one for each column of X. |
- Returns
-
module:analytics.SVR
B Self. The model has been created.
getModel() → Object
Get the model.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create a SVR model
var SVR = new analytics.SVR();
// get the properties of the model
var model = SVR.getModel();
- Returns
-
Object
B ThesvmModel
object containing the property:
1.svmModel.weights
- The weights of the model. Type module:la.Vector.
getParams() → module:analytics~SVMParam
Gets the SVR parameters.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create a new SVR object
var SVR = new analytics.SVR({ c: 10, eps: 1e-10, maxTime: 12000, verbose: true });
// get the parameters of SVR
var params = SVR.getParams();
- Returns
-
module:analytics~SVMParam
B Parameters of the regression model.
predict(X) → (number or module:la.Vector)
Sends vector through the model and returns the prediction as a real number.
Example
// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new SVR object
var SVR = new analytics.SVR({ c: 10 });
// create a matrix and vector for the model
var matrix = new la.Matrix([[1, -1], [1, 1]]);
var vector = new la.Vector([1, 1]);
// create the model by fitting the values
SVR.fit(matrix, vector);
// predict the value of the given vector
var vec2 = new la.Vector([-5, 1]);
var prediction = SVR.predict(vec2);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
X |
(module:la.Vector, module:la.SparseVector, module:la.Matrix, or module:la.SparseMatrix) |
|
Input feature vector or matrix with feature vectors as columns. |
- Returns
-
(number or module:la.Vector)
B Prediction:
1. Real number, ifX
is module:la.Vector or module:la.SparseVector.
2. module:la.Vector, ifX
is module:la.Matrix or module:la.SparseMatrix.
save(fout) → module:fs.FOut
Saves model to output file stream.
Example
// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
var fs = require('qminer').fs;
// create a new SVR object
var SVR = new analytics.SVR({ c: 10 });
// create a matrix and vector for the model
var matrix = new la.Matrix([[1, -1], [1, 1]]);
var vector = new la.Vector([1, 1]);
// create the model by fitting the values
SVR.fit(matrix, vector);
// save the model in a binary file
var fout = fs.openWrite('svr_example.bin');
SVR.save(fout);
fout.close();
// construct a SVR model by loading from the binary file
var fin = fs.openRead('svr_example.bin');
var SVR2 = new analytics.SVR(fin);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fout |
|
Output stream. |
- Returns
-
module:fs.FOut
B The output streamfout
.
setParams(param) → module:analytics.SVR
Sets the SVR parameters.
Example
// import analytics module
var analytics = require('qminer').analytics;
// create a new SVR object
var SVR = new analytics.SVR();
// set the parameters of the SVR object
SVR.setParams({ c: 10, maxTime: 12000 });
Parameter
Name | Type | Optional | Description |
---|---|---|---|
param |
|
Regression training parameters. |
- Returns
-
module:analytics.SVR
B Self. Updated the training parameters.