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

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

Yes

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

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 if X is module:la.Vector or module:la.SparseVector.
2. module:la.Vector, if X 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

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

 

Input feature matrix where columns correspond to feature vectors.

y

module:la.Vector

 

Input vector of targets, one for each column of X.

Returns

module:analytics.SVRB 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

ObjectB The svmModel 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~SVMParamB 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, if X is module:la.Vector or module:la.SparseVector.
2. module:la.Vector, if X 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

module:fs.FOut

 

Output stream.

Returns

module:fs.FOutB The output stream fout.

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

module:analytics~SVMParam

 

Regression training parameters.

Returns

module:analytics.SVRB Self. Updated the training parameters.