new OneVsAll([arg])

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });

Parameter

Name Type Optional Description

arg

module:analytics~oneVsAllParam

Yes

Construction arguments.

Methods

decisionFunction(X) → (module:la.Vector or module:la.Matrix)

Apply all models to the given vector and returns a vector of scores, one for each category. Semantic of scores depend on the provided binary model.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// create the data (matrix and vector) used to fit the model
var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
var vector = new la.Vector([0, 0, 1, 1]);
// fit the model
onevsall.fit(matrix, vector);
// create the vector for the decisionFunction
var test = new la.Vector([1, 2]);
// give the vector to the decision function
var prediction = onevsall.decisionFunction(test); // returns the vector of scores

Parameter

Name Type Optional Description

X

(module:la.Vector, module:la.SparseVector, module:la.Matrix, or module:la.SparseMatrix)

 

Feature vector or matrix with feature vectors as columns.

Returns

(module:la.Vector or module:la.Matrix)B The score and label of the input X:
1. module:la.Vector of scores, if X is of type module:la.Vector or module:la.SparseVector.
2. module:la.Matrix with columns corresponding to instances, and rows corresponding to labels, if X is of type module:la.Matrix or module:la.SparseMatrix.

fit(X, y) → module:analytics.OneVsAll

Apply all models to the given vector and returns category with the highest score.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// create the data (matrix and vector) used to fit the model
var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
var vector = new la.Vector([0, 0, 1, 1]);
// fit the model
onevsall.fit(matrix, vector);

Parameters

Name Type Optional Description

X

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

 

training instance feature vectors.

y

module:la.Vector

 

target category for each training instance. Categories must be integer numbers between 0 and oneVsAllParam.categories-1.

Returns

module:analytics.OneVsAllB Self. The models have been fitted.

getParams() → module:analytics~oneVsAllParam

Gets the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// get the parameters
// returns the JSon object
// { model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2, models: [] }
var params = onevsall.getParams();
Returns

module:analytics~oneVsAllParamB The constructor parameters.

predict(X) → (number or module:la.IntVector)

Apply all models to the given vector and returns category with the highest score.

Example

// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// create the data (matrix and vector) used to fit the model
var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
var vector = new la.Vector([0, 0, 1, 1]);
// fit the model
onevsall.fit(matrix, vector);
// create the vector for the prediction
var test = new la.Vector([1, 2]);
// get the prediction of the vector
var prediction = onevsall.predict(test); // returns 0

Parameter

Name Type Optional Description

X

(module:la.Vector, module:la.SparseVector, module:la.Matrix, or module:la.SparseMatrix)

 

Feature vector or matrix with feature vectors as columns.

Returns

(number or module:la.IntVector)B
1. number of the category with the higher score, if X is module:la.Vector or module:la.SparseVector.
2. module:la.IntVector of categories with the higher score for each column of X, if X is module:la.Matrix or module:la.SparseMatrix.

setParams(params) → module:analytics.OneVsAll

Sets the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// set the parameters
var params = onevsall.setParams({ model: analytics.SVR, modelParam: { c: 12, maxTime: 10000}, cats: 3, verbose: true });

Parameter

Name Type Optional Description

params

module:analytics~OneVsAllParam

 

The constructor parameters.

Returns

module:analytics.OneVsAllB Self. The parameters are changed.